Sha256: 019eec789cb0daa50386dafd85b64152b7f8f4e0fe9e92a0a1e0bd8c1dcad0a0

Contents?: true

Size: 560 Bytes

Versions: 9

Compression:

Stored size: 560 Bytes

Contents

require 'facets/more/functor.rb'

class Module

  def let

    Functor.new { |op, arg|

      ope = op.to_s.chomp('=')

      # reader
      if arg
        define_method(ope) {
          unless instance_variables.include?("@#{ope}")
            instance_variable_set("@#{ope}",arg)
          end
          instance_variable_get("@#{ope}")
        }
      else
        attr ope
      end

      # writer
      attr_writer ope

    }

  end

end



class Test

  class Example

    let.a = 10
    let.b = 20

  end

end

te = Test::Example.new
p te.a
p te.b



Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
facets-1.4.1 forge/core/module/let.rb
facets-1.4.2 forge/core/module/let.rb
facets-1.4.3 forge/core/module/let.rb
facets-1.4.4 forge/core/module/let.rb
facets-1.4.5 snip/core/module/let.rb
facets-1.8.49 work/core/module/let.rb
facets-1.8.0 work/core/module/let.rb
facets-1.8.20 work/core/module/let.rb
facets-1.8.8 work/core/module/let.rb