This file contains hidden or 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
rvm: # list all the Rubies you want to test against | |
- 1.9.3 | |
- jruby | |
- rbx | |
script: "bundle exec rake test" # your test command goes here |
This file contains hidden or 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 DoNotDisturb | |
def initialize | |
@desk = InformationDesk.new | |
end | |
def method_missing(name, *args) | |
unless name.to_s == "emergency" | |
hour = Time.now.hour | |
raise "Out for lunch" if hour >= 12 && hour < 14 | |
end |
This file contains hidden or 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 InformationDesk | |
def emergency | |
# Call emergency... | |
"emergency() called" | |
end | |
def flights | |
# Provide flight information... | |
"flights() called" | |
end |
This file contains hidden or 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 Performer | |
def method_missing(name, *args) | |
"The duck will #{name}: #{args[0]}" | |
end | |
end | |
duck = Performer.new | |
duck.sing("Quacking in the Rain") # => "The duck will sing: Quacking in the Rain" | |
duck.dance("Swan Lake") # => "The duck will dance: Swan Lake" |
This file contains hidden or 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
# ===================== | |
# Spell: Symbol to Proc | |
# ===================== | |
# Convert a symbol to a block that calls a single method. | |
[1, 2, 3, 4].map(&:even?) # => [false, true, false, true] | |
# For more information: http://www.pragprog.com/titles/ppmetr/metaprogramming-ruby |
This file contains hidden or 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
# ================= | |
# Spell: Self Yield | |
# ================= | |
# Pass self to the current block. | |
class Person | |
attr_accessor :name, :surname | |
def initialize |
This file contains hidden or 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
# ================= | |
# Spell: Scope Gate | |
# ================= | |
# Isolate a scope with the class, module, or def keyword. | |
a = 1 | |
defined? a # => "local-variable" | |
module MyModule |
This file contains hidden or 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
# ============== | |
# Spell: Sandbox | |
# ============== | |
# Execute untrusted code in a safe environment. | |
def sandbox(&code) | |
proc { | |
$SAFE = 2 | |
yield |
This file contains hidden or 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
# ======================= | |
# Spell: Pattern Dispatch | |
# ======================= | |
# Select which methods to call based on their names. | |
$x = 0 | |
class C | |
def my_first_method |