Created
December 30, 2022 18:00
-
-
Save noelrappin/a51d0e271126b0d2fdc4a75910b4d8a4 to your computer and use it in GitHub Desktop.
Splat check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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