This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
|
Original Post: Simpler Ways
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
|
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded
|
|
Advertisement
|
1. Less explicit to_s.
Like in joining arrays: records.map { |r| r.to_s }.join "\n"
Agg, get away casting! Could just be: records * "\n"
2. Forgetting grep works with classes.
I’ll be searching for a class: animals.find_all { |a| a.is_a? Hawk }
Rather: animals.grep Hawk
3. Structs for simple classes.
Object still needs an attrs
method. Struct has members
.
Object uses instance_variable_set
. Struct uses []=
.
Read: Simpler Ways