Skip to content

Instantly share code, notes, and snippets.

@fronx
Created April 28, 2011 13:25
Show Gist options
  • Select an option

  • Save fronx/946337 to your computer and use it in GitHub Desktop.

Select an option

Save fronx/946337 to your computer and use it in GitHub Desktop.
def _?(o, method, &block)
o.respond_to?(method) ? o : block.call(o)
end
def eachize(one_or_more)
_?(one_or_more, :each) { |o| [o] }
end
def foo(one_or_more)
eachize(one_or_more).each do |o|
puts o
end
end
foo(3)
# 3
foo([1,2])
# 1
# 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment