Class: Hash
Instance Method Summary collapse
- #apricot_call(key, default = nil) ⇒ Object
-
#apricot_inspect ⇒ Object
(also: #apricot_str)
Adapted from Hash#inspect.
- #to_seq ⇒ Object
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_inspect ⇒ Object 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_seq ⇒ Object
111 112 113 |
# File 'lib/apricot/ruby_ext.rb', line 111 def to_seq each_pair.to_a.to_seq end |