Sha256: 761c132aec576b8d31ef438b1771e7e6b2a294ba08d62fd69c15385ade554a18

Contents?: true

Size: 851 Bytes

Versions: 1

Compression:

Stored size: 851 Bytes

Contents

require 'pathname'

module At
  VERSION ||= Pathname.new(__FILE__).dirname.join('..', 'VERSION').read
  
  class MethodToInstanceVariableProxy
    def initialize(parent)
      @parent = parent
    end
    
    def method_missing(meth, *args, &blk)
      @parent.instance_eval do
        if match = meth.to_s.match(/(.*)\=$/)
          instance_variable_set("@#{match[1]}", args)
        else
          if block_given?
            instance_variable_set("@#{meth}", args.empty? ? args : blk.call)
          else
            if args.empty?
              instance_variable_get("@#{meth}")
            else
              instance_variable_set("@#{meth}", value)
            end
          end
        end
      end
    end
  end
  
  def at
    @_method_to_instance_variable_proxy ||= MethodToInstanceVariableProxy.new(self)
  end
end

require 'at/core_ext'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
at-0.1.0 lib/at.rb