-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Robert Klemme wrote: | | But, as Todd also mentions, this cries for a Hash. With a Hash method | #discount is basically superfluous. | | DISCOUNT = Hash.new(0).update( | :friend => 40, | :vet => 100, | :super_vet => 160 | ).freeze | | Then a method call essentially becomes | | DISCOUNT[:foo] I don't like this. | instead of | | discount :foo But I like that. So, let's do a Classic version (pardon the pun): class Discounts ~ attr_reader :friend, :vet, :super_vet ~ def initialize ~ @friend, @vet, @super_vet = 40, 100, 160 ~ end ~ def method_missing ~ 0 # The default 'discount' ~ end end discount_for = Discounts.new discount_for vet => 100 discount_for somebody_else => 0 Beware of bugs; I've only proved the code correct, not tested it. - -- Phillip Gawlowski Twitter: twitter.com/cynicalryan Blog: http://justarubyist.blogspot.com ~ - You know you've been hacking too long when... ...you discover that you're balancing your checkbook in octal. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkggeIYACgkQbtAgaoJTgL9FBwCfbEkHYMGYwGyyjig79uEtpJEJ pt8AniofvYQwftnufso/za+DfgfTPNLY =+K4V -----END PGP SIGNATURE-----