iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up
Next »

Summary

Wrapping up the Ruby track with what you can ship and where to go next.

What you learned + first Rails 8 model

EXAMPLE
# Ruby summary

You can now:

- Read and write idiomatic Ruby - blocks, procs, lambdas
- Use core enumerable methods: map, select, reduce, each_with_object
- Define classes, modules, and mixins; understand method lookup
- Handle exceptions with begin/rescue/ensure
- Reach for Bundler, Rake, and RSpec without thinking
- Build small Sinatra apps and understand Rack
- Recognise Rails conventions even outside a Rails app

# Your next step - a Rails 8 model + scope

# app/models/order.rb
class Order < ApplicationRecord
  belongs_to :user
  has_many :items, dependent: :destroy

  enum status: { open: 0, paid: 1, shipped: 2, cancelled: 3 }

  validates :total, numericality: { greater_than_or_equal_to: 0 }

  scope :recent, -> { where('created_at > ?', 30.days.ago) }
  scope :high_value, ->(min = 1000) { where('total > ?', min) }

  def display_total
    ActiveSupport::NumberHelper.number_to_currency(total / 100.0)
  end
end

# Order.paid.recent.high_value(2000).order(created_at: :desc)
# is a real, indexable, chainable query.

Why it matters

Ruby rewards reading. Pick a gem you depend on and read its lib/ directory; you will learn more than from any tutorial.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
# Next: Rails deep dive, Sidekiq, Hotwire, gems publishing.
Try it Yourself »

Discussion

Loading…

Next »