Skip to content

Instantly share code, notes, and snippets.

@hardbap
Created August 8, 2012 15:24
Show Gist options
  • Save hardbap/3295897 to your computer and use it in GitHub Desktop.
Save hardbap/3295897 to your computer and use it in GitHub Desktop.
cool block passing from girl_friday
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