Created
December 5, 2012 12:43
-
-
Save maxidr/4215221 to your computer and use it in GitHub Desktop.
Ruby struct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# instead of: class User < Struct.new(:first, :last) ... end | |
User = Struct.new(:first, :last) do | |
def full | |
"#{first} #{last}" | |
end | |
end | |
james = User.new('James', 'Gray') | |
# from https://speakerdeck.com/jeg2/10-things-you-didnt-know-ruby-could-do |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment