Sha256: a01a458866ffb6edf19d3c36c39bbea0a434d4cc0752f20f9d81120466fcda65

Contents?: true

Size: 941 Bytes

Versions: 9

Compression:

Stored size: 941 Bytes

Contents

###
### $Rev$
### $Release: 0.7.2 $
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
###

module Kwalify

  module Util

    ##
    ## add hash-like methods
    ##
    module HashLike

      def [](key)
        instance_variable_get("@#{key}")
      end

      def []=(key, val)
        instance_variable_set("@#{key}", val)
      end

      #--
      #def keys()
      #  instance_variables().collect { |name| name[1, name.length-1] }
      #end
      #++

      def key?(key)
        instance_variables().include?("@#{key}")
      end
      if Object.instance_methods.include?('instance_variable_defined?')
        def key?(key)
          instance_variable_defined?("@#{key}")
        end
      end

      def each   # not necessary
        instance_variables().each do |name|
          key = name[1, name.length-1]
          val = instance_variable_get(name)
          yield(key, val)
        end
      end

    end

  end

end

Version data entries

9 entries across 7 versions & 4 rubygems

Version Path
dc-kwalify-1.0.0 lib/kwalify/util/hashlike.rb
dc-kwalify-0.7.2 lib/kwalify/util/hashlike.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/lib/kwalify/util/hashlike.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/lib/kwalify/util/hashlike.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/lib/kwalify/util/hashlike.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/lib/kwalify/util/hashlike.rb
tpkg-2.3.5 lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb
tpkg-2.3.4 lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb
kwalify-0.7.2 lib/kwalify/util/hashlike.rb