Skip to content

Instantly share code, notes, and snippets.

@hzm-s
Last active January 2, 2016 13:58
Show Gist options
  • Save hzm-s/8313204 to your computer and use it in GitHub Desktop.
Save hzm-s/8313204 to your computer and use it in GitHub Desktop.
Structなクラスをハッシュでnew
class Lens < Struct.new(:name, :mm, :f, :close_up, :generation)
def initialize(attrs)
super(*self.class.members.inject([]) {|r, x| r << attrs[x] })
end
end
Lens.new(
f: 2,
generation: '3rd',
name: 'Summicron',
mm: 50,
close_up: false
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment