Sha256: c9cdc56f1fd7317656b98a6758cefd8ed71aca7fa0ae19aa87e02fa5cc909e16

Contents?: true

Size: 767 Bytes

Versions: 3

Compression:

Stored size: 767 Bytes

Contents

#--
# :TODO: Perhaps need to make a check against overriding Megas annotated version.
#++

class Module

  # Create an attribute method for both getting
  # and setting an instance variable.
  #
  #   attr_setter :a
  #
  # _is equivalent to_
  #
  #   def a(*args)
  #     if args.size > 0
  #       @a = args[0]
  #       self
  #     else
  #       @a
  #     end
  #   end
  #
  def attr_setter(*args)

    make = {}
    args.each { |a|
      make[:"#{a}"] = %{
        def #{a}(*args)
          args.size > 0 ? ( @#{a}=args[0] ; self ) : @#{a}
        end
      }
    }
    module_eval( make.values.join("\n") )

    return make.keys
  end

end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
# TODO

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-1.0.3 packages/core/lib/facet/module/attr_setter.rb
facets-0.9.0 lib/nano/module/attr_setter.rb
facets-1.0.0 lib/facet/module/attr_setter.rb