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
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
>> 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
module ActiveSupport | |
# Wrapping a string in this class gives you a prettier way to test | |
# for equality. The value returned by <tt>Rails.env</tt> is wrapped | |
# in a StringInquirer object so instead of calling this: | |
# | |
# Rails.env == "production" | |
# | |
# you can call this: | |
# | |
# Rails.env.production? |
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
# sweet! | |
>> m.food = "hi" | |
=> "hi" | |
>> m.food.hi? | |
=> true | |
>> m.food.apple? | |
=> false | |
>> m.food = "apple" | |
=> "apple" | |
>> m.food.apple? |
OlderNewer