Ruby star (*) role

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Help yourself to learn a word :

Making the star asterrisk['æstərɪsk]

 

=========================I is symmetric about the dividing line, the start of text=========================

  

1 multiplication function

 

 3 * 4 == 12 # => true

 

2 array *integer

 

[1,2 ,[3 , [4 ,5]]] *2 = [1,2 ,[3 , [4 ,5]] , 1,2 ,[3 , [4 ,5]]]  

 

3 string *integer

 

"hello"*2 = "hellohello"  

 

4 create an array

 

*a = 1,3,"as"  # => Equivalent to a = [1,3, "as"]  

 

5 array parameter when the prefix eg:

 

a= [1 , 2]  
testFun(*a) == testFun(1 , 2) != testFun([1,2])  

 

Making such as gem in redis-namespace code:

 

Hash[*key.map {|k, v| [ add_namespace(k), v ]}.flatten]

 

Again:

 

Hash[:a, 1, :b, 2]  # => {:a => 1, :b => 2}

array = [:a, 1, :b, 2]
Hash[array]   # => {}
Hash[*array]  # Equivalent to Hash[:a, 1, :b, 2] 
              #=> {:a => 1, :b => 2}

 

Reference connection:

 

   https://github.com/resque/redis-namespace/blob/master/lib/redis/namespace.rb#L389

   

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Avery at January 10, 2014 - 12:42 AM