Today I’m looking at facets’ Hash#to_struct. I use structs in my code when I want to store some complex data but don’t need to full Ruby class. The Code 1 2 3 4 # File lib/core/facets/hash/to_struct.rb, line 12 def to_struct(struct_name) Struct.new(struct_name,*keys).new(*values) end# File lib/core/facets/hash/to_struct.rb, line 12 def to_struct(struct_name) Struct.new(struct_name,*keys).new(*values) end Example 1 2 3 4 …
Category: Articles
Daily Code Reading #2 – Facets Hash#zipnew
I’m continuing my look at Ruby Facets today, this time looking at another Hash method. I use Hashes everyday in Rails programming so if I can pick up some new techniques, I can put them to use right away. Today’s subject is Hash#zipnew. The Code 1 2 3 4 5 6 # File lib/core/facets/hash/zipnew.rb, line …
Daily Code Reading #1 – Facets Hash#autonew
I’m starting this series by taking a look at Ruby Facets. Facets is a collection of Ruby core and Ruby standard library extensions. It has a lot of good code embedded in it from many contributors so it should be a good place to start looking for some new ideas. The Code 1 2 3 …
Code Reading – New Ideas and New Solutions
My daily refactorings have improved my existing code up to my current knowledge of Ruby. Now I need a way to learn new ideas and ways to write Ruby. I’m going to start doing a daily code reading and review every day: posting it reading over it taking notes on the interesting techniques try to …
Pausing Daily Refactors
After almost four months of daily refactors, I’ve decided to pause them. They have been very successful and helped me overcome a lot of the fears I’ve had with programming. I just feel that they have lost some of their value now and I want to move on to another interesting idea for self training. …