Skip to content

Instantly share code, notes, and snippets.

@chrisfarber
Last active March 28, 2017 20:03
Show Gist options
  • Save chrisfarber/0cae4f66de7194f3c42837931e151913 to your computer and use it in GitHub Desktop.
Save chrisfarber/0cae4f66de7194f3c42837931e151913 to your computer and use it in GitHub Desktop.
exploring ruby's nuances
module Thing
module_function
def thing(&block)
(1..3).map(&block)
end
def other_thing
thing do |v|
next(:surprise) if v == 2
v
end
end
def other_other_thing
thing do |v|
return(:surprise) if v == 3
v
end
end
end
puts(Thing.other_thing.inspect) # output: [1, :surprise, 3]
puts(Thing.other_other_thing.inspect) # output: :surprise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment