Sha256: ad9c7e8445a833ff023ddcb1cb6308175cbe8a093c3781612e25c32b68df9d19
Contents?: true
Size: 943 Bytes
Versions: 1
Compression:
Stored size: 943 Bytes
Contents
module Rouge class InheritableHash < Hash def initialize(parent=nil) @parent = parent end def [](k) _sup = super return _sup if own_keys.include?(k) _sup || parent[k] end def parent @parent ||= {} end def include?(k) super or parent.include?(k) end def each(&b) keys.each do |k| b.call(k, self[k]) end end alias own_keys keys def keys keys = own_keys.concat(parent.keys) keys.uniq! keys end end class InheritableList include Enumerable def initialize(parent=nil) @parent = parent end def parent @parent ||= [] end def each(&b) return enum_for(:each) unless block_given? parent.each(&b) own_entries.each(&b) end def own_entries @own_entries ||= [] end def push(o) own_entries << o end alias << push end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rouge-0.2.0 | lib/rouge/util.rb |