Skip to content

Instantly share code, notes, and snippets.

@rewinfrey
Last active August 29, 2015 14:09
Show Gist options
  • Save rewinfrey/3133ce090438f6247876 to your computer and use it in GitHub Desktop.
Save rewinfrey/3133ce090438f6247876 to your computer and use it in GitHub Desktop.
model like struct class
class Location < Struct.new(:city,
:state,
:zipcode)
def initialize(from_hash)
super(*from_hash.values_at(*members))
end
def display_city
city.capitalize
end
end
location_hash = {
:city => "City",
:state => "State",
:zipcode => 60613
}
location = Location.new(location_hash)
location.display_city # => "City"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment