* and ** in ruby methods and more.
In the ruby you can use ** or hash in the methods. Here is the some examples plz follow this with me.
In the ruby you can use ** or hash in the methods. Here is the some examples plz follow this with me.
[37] pry(main)> def test2(data={})
[37] pry(main)* ap data
[37] pry(main)* end
Here you can put any number of data using symbol key and values like we used for creating hash and this will be captured by element.
[40] pry(main)> test2(hello:'data',say:'data')
{
:hello => "data",
:say => "data"
}
=> nil
Note: Here we have used gem 'awesome_print' for the beautiful print.
There is another way of writing the same function.
[28] pry(main)> def test(**data)
[28] pry(main)* print data
[28] pry(main)* end
: