Skip to content

Instantly share code, notes, and snippets.

module ActionController
class MiddlewareStack < Array
class Middleware
attr_reader :klass, :args, :block
def initialize(klass, *args, &block)
@klass = klass.is_a?(Class) ? klass : klass.to_s.constantize
@args = args
@block = block
end
# activesupport/lib/active_support/core_ext/module/delegation.rb
class Module
def delegate(*methods)
options = methods.pop
unless options.is_a?(Hash) && to = options[:to]
raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
end
if options[:prefix] == true && options[:to].to_s =~ /^[^a-z_]/
We couldn’t find that file to show.
We couldn’t find that file to show.
>> "hello" & "goodbye"
NoMethodError: undefined method `&' for "hello":String
from (irb):31
>> 1 & 2
=> 0
>> alien = true
>> speaks_english = false
# 1
>> alien and speaks_english ? 'hello' : '**silence**'
=> "**silence**"
# 2
>> alien && speaks_english ? 'hello' : '**silence**'
=> "**silence**"
>> hammer_of_truth = true
>> anvil_of_false = false
>> sword = hammer_of_truth && anvil_of_false
=> false
>> sword
=> false
>> sword = hammer_of_truth and anvil_of_false
=> false
>> !!active
=> true
>> active = false
=> false
>> !!active
=> false
>> active = nil
# It doesn't work this way!
>> m = Momoro.new
=> #<Momoro id: nil, name: nil, food: nil, created_at: nil, updated_at: nil>
>> m.food = "basil"
>> m.food.basil?
=> true
>> m.food = "pillows"
>> m.food.pillows?
class Momoro < ActiveRecord::Base
def food
ActiveSupport::StringInquirer.new("basil")
end
end