Skip to content

Instantly share code, notes, and snippets.

@ledestin
Last active December 23, 2015 10:39
Show Gist options
  • Save ledestin/6623382 to your computer and use it in GitHub Desktop.
Save ledestin/6623382 to your computer and use it in GitHub Desktop.
def Point(*args)
case args.first
when Integer then Point.new(*args)
when String then Point.new(*args.first.split(':').map(&:to_i))
when ->(arg){ arg.respond_to?(:to_point) }
args.first.to_point
when ->(arg){ arg.respond_to?(:to_ary) }
Point.new(*args.first.to_ary) else
raise TypeError, args.inspect} to Point" end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment