Sha256: 16f02f181bc622b5fbcf5b2a3fb22415e08474a187b4ad1d7aa0cd58ffe1a8dc
Contents?: true
Size: 628 Bytes
Versions: 36
Compression:
Stored size: 628 Bytes
Contents
# # a nice feature is that all fattrs are enumerated in the class. this, # combined with the fact that the getter method is defined so as to delegate # to the setter when an argument is given, means bulk initialization and/or # fattr traversal is very easy. # require 'fattr' class C fattrs %w( x y z ) def fattrs self.class.fattrs end def initialize fattrs.each_with_index{|a,i| send a, i} end def to_hash fattrs.inject({}){|h,a| h.update a => send(a)} end def inspect to_hash.inspect end end c = C.new p c.fattrs p c c.x 'forty-two' p c.x
Version data entries
36 entries across 36 versions & 3 rubygems