Class: Array
- Defined in:
- lib/amp/dependencies/maruku/structures_inspect.rb,
lib/amp/support/support.rb
Direct Known Subclasses
MaRuKu::AttributeList, MaRuKu::In::Markdown::BlockLevelParser::BlockContext
Instance Method Summary collapse
-
#delete_range(range) ⇒ Object
Deletes the given range from the array, in-place.
- #inspect_more(compact, join_string, add_brackets = true) ⇒ Object
-
#second ⇒ Object
Returns the second item in the array.
- #short_hex ⇒ Object (also: #short)
-
#sum(identity = 0, &block) ⇒ Array
Sums all the items in the array.
- #to_hash ⇒ Object
Instance Method Details
#delete_range(range) ⇒ Object
Deletes the given range from the array, in-place.
624 625 626 627 628 629 630 631 632 |
# File 'lib/amp/support/support.rb', line 624 def delete_range(range) newend = (range.end < 0) ? self.size + range.end : range.end newbegin = (range.begin < 0) ? self.size + range.begin : range.begin newrange = Range.new newbegin, newend pos = newrange.first newrange.each {|i| self.delete_at pos } self end |
#inspect_more(compact, join_string, add_brackets = true) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/amp/dependencies/maruku/structures_inspect.rb', line 36 def inspect_more(compact, join_string, add_brackets=true) s = map {|x| x.kind_of?(String) ? x.inspect : x.kind_of?(MaRuKu::MDElement) ? x.inspect(compact) : (raise "WTF #{x.class} #{x.inspect}") }.join(join_string) add_brackets ? "[#{s}]" : s end |
#second ⇒ Object
Returns the second item in the array
621 |
# File 'lib/amp/support/support.rb', line 621 def second; self[1]; end |
#short_hex ⇒ Object Also known as: short
638 639 640 |
# File 'lib/amp/support/support.rb', line 638 def short_hex map {|e| e.short_hex } end |
#sum(identity = 0, &block) ⇒ Array
Sums all the items in the array.
From activesupport-2.3.5, activesupport/lib/active_support/core_ext/enumerable.rb, line 57
609 610 611 612 613 614 615 |
# File 'lib/amp/support/support.rb', line 609 def sum(identity=0, &block) if block_given? map(&block).sum(identity) else inject { |sum, element| sum + element } || identity end end |
#to_hash ⇒ Object
634 635 636 |
# File 'lib/amp/support/support.rb', line 634 def to_hash inject({}) {|h, (k, v)| h[k] = v; h } end |