Sha256: ead538086c3b55e707ebe27b32ee4f1f5ae36eccf6c3b380c5ff654d3111bf51
Contents?: true
Size: 1.05 KB
Versions: 42
Compression:
Stored size: 1.05 KB
Contents
module Inch module Utils # Extend a class with ReadWriteMethods and you will gain the +rw_methods+ # macro. # # class User # extend ReadWriteMethods # rw_methods :name, :admin # end # # This implements read methods that act as writer methods when called # with a value parameter: # # user = User.new # user.name # => nil # user.name "Adam" # user.name # => "Adam" # module ReadWriteMethods # Implements a read method that acts as writer if called with a value # # @return [void] def rw_method(name) class_eval """ def #{name}(value = nil) if value.nil? @#{name} else @#{name} = value end end """ end # Implements multiple read(write) methods with the given +names+ # # @param names [Array<String,Symbol>] # @return [void] def rw_methods(*names) [names].flatten.each { |name| rw_method(name) } end end end end
Version data entries
42 entries across 42 versions & 1 rubygems