Created
August 8, 2012 15:24
-
-
Save hardbap/3295897 to your computer and use it in GitHub Desktop.
cool block passing from girl_friday
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 Ninja | |
def initialize(name, &block) | |
@name = name | |
@move = block | |
end | |
def attack | |
@move.call | |
end | |
end | |
one = Ninja.new('one') { puts 'karate chop' } | |
one.attack | |
# => karate chop | |
def kick | |
puts 'kick' | |
end | |
two = Ninja.new('two', &method(:kick)) | |
two.attack | |
# => kick |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment