This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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_]/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> "hello" & "goodbye" | |
NoMethodError: undefined method `&' for "hello":String | |
from (irb):31 | |
>> 1 & 2 | |
=> 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> alien = true | |
>> speaks_english = false | |
# 1 | |
>> alien and speaks_english ? 'hello' : '**silence**' | |
=> "**silence**" | |
# 2 | |
>> alien && speaks_english ? 'hello' : '**silence**' | |
=> "**silence**" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> !!active | |
=> true | |
>> active = false | |
=> false | |
>> !!active | |
=> false | |
>> active = nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Momoro < ActiveRecord::Base | |
def food | |
ActiveSupport::StringInquirer.new("basil") | |
end | |
end |
OlderNewer