Skip to content

Instantly share code, notes, and snippets.

@sferik
Created November 18, 2012 05:54
Show Gist options
  • Save sferik/4103815 to your computer and use it in GitHub Desktop.
Save sferik/4103815 to your computer and use it in GitHub Desktop.
Baloney sandwich
def baloney
puts "baloney"
end
def bread
puts "bread"
end
def sandwich(filling)
bread
filling
bread
end
sandwich(baloney)
@steveklabnik
Copy link

that's what I'd guess too.

@corasaurus-hex
Copy link

Fixed it:

def baloney
  puts "baloney"
end

def bread
  puts "bread"
end

def sandwich(filling)
  bread
  filling.call
  bread
end

sandwich(method(:baloney))

@mogox
Copy link

mogox commented Nov 19, 2012

Hey @nate about the fix. Wouldn't it be more natural something like this?

def baloney
  puts "baloney"
end

def bread
  puts "bread"
end

def sandwich(&block)
  bread
  yield
  bread
end

sandwich { baloney }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment