Skip to content

Instantly share code, notes, and snippets.

We couldn’t find that file to show.
We couldn’t find that file to show.
>> alien = true
>> speaks_english = false
# 1
>> alien and speaks_english ? 'hello' : '**silence**'
=> "**silence**"
# 2
>> alien && speaks_english ? 'hello' : '**silence**'
=> "**silence**"
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_]/
>> "hello" & "goodbye"
NoMethodError: undefined method `&' for "hello":String
from (irb):31
>> 1 & 2
=> 0
>> 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
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?
# sweet!
>> m.food = "hi"
=> "hi"
>> m.food.hi?
=> true
>> m.food.apple?
=> false
>> m.food = "apple"
=> "apple"
>> m.food.apple?