This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Petty Theft from Python
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Lucas Carlson has lifted a few method ideas from Python: starts_with? and ends_withs?, as well as in?. Which got me thinking about an unfinished thought from FOSCON. I’d really like Python’s dict method.
def Hash.[]( enum )
enum.inject({}) do |hsh,(k,v)|
hsh[k] = v
hsh
end
end
I know there’s already a Hash::[] but I really like this better. An array of pairs makes so much more sense than a flattened array of arbitrary length.