Skip to content

Instantly share code, notes, and snippets.

@lazyatom
Forked from JEG2/struct.md
Created June 4, 2013 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazyatom/5708510 to your computer and use it in GitHub Desktop.
Save lazyatom/5708510 to your computer and use it in GitHub Desktop.

How Should We Use Struct?

The Choice

It's common in Ruby to see some code setup a Struct like this:

class Specialized < Struct.new(:whatever)
  # ... define custom methods here...
end

Struct supports this kind of modification using a block though, so the above could be written as:

Specialized = Struct.new(:whatever) do
  # ... define custom methods here...
end

Those are the possibilities.

My Opinion

There's no right or wrong way to handle this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment