is it possible to use hash keys as a first level variables inside ruby method? -
i'll try explain myself little bit more
# lets have hash options = {a: 1, b: 2} # , here i'm calling method some_method(options) def some_method(options) # instead of using options[:a] i'd use a. options.delete_nesting_and_create_vars + b # :a + :b good.
thanks!
if options fixed, :a
, :b
keys, can write method this:
def some_method(a:, b:) + b end options = {a: 1, b: 2} some_method(options) #=> 3
Comments
Post a Comment