06 Sep '12, 2am

All about Struct

This guest post is by Steve Klabnik . Steve is a Rubyist, writer, and teaches Ruby and Rails classes with Jumpstart Lab. He maintains Draper, Hackety Hack, and Shoes, and contributes to Rails from time to time. O ne of my favorite classes in Ruby is Struct , but I feel like many Rubyists don’t know when to take advantage of it. The standard library has a lot of junk in it, but Struct and OStruct are super awesome. Struct If you haven’t used Struct before, here’s the documentation of Struct from the Ruby standard library . Structs are used to create super simple classes with some instance variables and a simple constructor. Check it: Struct.new("Point", :x, :y) #=> Struct::Point origin = Struct::Point.new(0,0) #=> # Nobody uses it this way, though. Here’s the way I first saw it used: class Point < Struct.new(:x, :y) end origin = Point.new(0,0) Wait, what? Inherit…from an in...

Full article: http://rubylearning.com/blog/2012/09/06/all-about-struct/

Tweets

All about Struct

rubyflow.com 06 Sep '12, 2am

All about Struct Posted by IndianGuru on September 06, 2012 — 0 comments Steve Klabnik shows us how to take advantage of S...

Все о Struct и OStruct

rubyflow.ru 06 Sep '12, 6am

Откровенного говоря не все, но вполне достаточно, чтобы задуматься об использовании Struct и OStruct или хотя бы изучить д...

striuct (0.3.1): validatable, inheritable, And ...

rubygems.org 01 Sep '12, 4pm

striuct 0.3.1 validatable, inheritable, And more Struct++ features :) install gem install striuct Download Documentation S...