In **Ruby, I want to fetch all keys and values at once without needing to iterate through the hash.
The keys are variables and the values of data type boolean.
In the new Example, the only parameters, which are exchangeable, are var1 => true and var2 => true.
So, I want that the hash keys are treated as keywords.
New Example:
var1 = "Attr1"
var2 = "Attr2"
var3 = "Attr2"
hash = {var1 => true, var2 => true}
def method(h = {})
puts("Works")
end
method(hash, var3 => true) #Error
Old Example:
hash = {var1 => true, var2 => false}
self.some_method_i_cant_change_1(var1 => true, var2 => false, var3 => true)
self.some_method_i_cant_change_2(var1 => true, var2 => false, var3 => true)
... n methods
self.some_method_i_cant_change_n(var1 => true, var2 => false, var3 => true)
It's not possible to pass the hash to that method directly.
So, self.some_method_i_cant_change(hash, var3 => true) isn't allowed
self.some_method_i_cant_change(**hash)foo(var1 => true, var2 => false)is equivalent tofoo({var1 => true, var2 => false})orfoo(hash)withhash = {var1 => true, var2 => false}. Can you double check how the method is called?a={"h" =>1, "b" => 2}def method(option={})method("z"=>1,a)results in an error. Andmethod("z"=>1,**a)does worksome_method_i_cant_change_*methods are intended to use their arguments.