Skip to content

Instantly share code, notes, and snippets.

@noelrappin
Created December 30, 2022 18:00
Show Gist options
  • Save noelrappin/a51d0e271126b0d2fdc4a75910b4d8a4 to your computer and use it in GitHub Desktop.
Save noelrappin/a51d0e271126b0d2fdc4a75910b4d8a4 to your computer and use it in GitHub Desktop.
Splat check
class Consumer
def takes_args(a, b, c)
p "#{a} #{b} #{c}"
end
def takes_keys(a:, b:, c:)
p "#{a} #{b} #{c}"
end
end
class NotAnArrayOrAHash
def initialize(a, b, c)
@a = a
@b = b
@c = c
end
def to_a
[@a, @b, @c]
end
def to_hash
{a: @a, b: @b, c: @c}
end
end
obj = NotAnArrayOrAHash.new(1, 2, 3)
c = Consumer.new
c.takes_args(*obj)
c.takes_keys(**obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment