Class: Hash

Inherits:
Object show all
Defined in:
lib/apricot/ruby_ext.rb

Instance Method Summary collapse

Instance Method Details

#apricot_call(key, default = nil) ⇒ Object



105
106
107
# File 'lib/apricot/ruby_ext.rb', line 105

def apricot_call(key, default = nil)
  fetch(key, default)
end

#apricot_inspectObject Also known as: apricot_str

Adapted from Hash#inspect. Outputs Apricot hash syntax, e.g. 1, :b 2



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/apricot/ruby_ext.rb', line 87

def apricot_inspect
  return '{}' if size == 0

  str = '{'

  return '{...}' if Thread.detect_recursion self do
    each_item do |item|
      str << item.key.apricot_inspect
      str << ' '
      str << item.value.apricot_inspect
      str << ', '
    end
  end

  str.shorten!(2)
  str << '}'
end

#to_seqObject



111
112
113
# File 'lib/apricot/ruby_ext.rb', line 111

def to_seq
  each_pair.to_a.to_seq
end