Class: Yargi::ElementSet
- Inherits:
-
Array
- Object
- Array
- Yargi::ElementSet
- Defined in:
- lib/yargi/element_set.rb
Overview
Main module of VertexSet and EdgeSet
Class Method Summary collapse
-
.[](*elements) ⇒ Object
Creates a ElementSet instance using elements varargs.
Instance Method Summary collapse
-
#+(right) ⇒ Object
See Array.+.
-
#-(right) ⇒ Object
See Array.-.
-
#[](*args) ⇒ Object
See Array.[].
-
#add_marks(marks = nil) ⇒ Object
(also: #merge_marks)
When marks is provided, the invocation is fired to all group elements.
-
#compact ⇒ Object
See Array.compact.
-
#concat(other) ⇒ Object
See Array.concat.
-
#dup ⇒ Object
Same as Array.dup.
-
#each_cons(n) ⇒ Object
See Enumerable.each_cons.
-
#each_slice(n) ⇒ Object
See Enumerable.each_slice.
-
#filter(predicate = nil, &block) ⇒ Object
Filters this set with a ‘predicate and block’ predicate (see Yargi::Predicate).
-
#find_all(&block) ⇒ Object
See Enumerable.find_all.
-
#flatten ⇒ Object
See Array.flatten.
-
#get_mark(key) ⇒ Object
Collects result of get_mark invocation on each element of the group and returns it as an array.
-
#grep(pattern, &block) ⇒ Object
See Enumerable.grep.
-
#partition(&block) ⇒ Object
See Enumerable.reject.
-
#reject(&block) ⇒ Object
See Enumerable.reject.
-
#reverse ⇒ Object
See Array.reverse.
-
#select(&block) ⇒ Object
See Enumerable.select.
-
#set_mark(key, value, dup = true) ⇒ Object
Fired to each element of the group.
-
#sort(&block) ⇒ Object
See Array.sort.
-
#tag(*modules) ⇒ Object
Fired to each element of the group.
-
#uniq ⇒ Object
See Array.uniq.
Class Method Details
.[](*elements) ⇒ Object
Creates a ElementSet instance using elements varargs.
11 12 13 |
# File 'lib/yargi/element_set.rb', line 11 def self.[](*elements) ElementSet.new(elements) end |
Instance Method Details
#+(right) ⇒ Object
See Array.+
60 61 62 |
# File 'lib/yargi/element_set.rb', line 60 def +(right) # :nodoc: # extend_result(super(right)) end |
#-(right) ⇒ Object
See Array.-
65 66 67 |
# File 'lib/yargi/element_set.rb', line 65 def -(right) # :nodoc: # extend_result(super(right)) end |
#[](*args) ⇒ Object
See Array.[]
54 55 56 57 |
# File 'lib/yargi/element_set.rb', line 54 def [](*args) # :nodoc: # result = super(*args) Array===result ? extend_result(result) : result end |
#add_marks(marks = nil) ⇒ Object Also known as: merge_marks
When marks is provided, the invocation is fired to all group elements. When a block is given, it is called on each element, passing it as argument. If the block returns a hash, that hash is installed as marks on the iterated element. The two usages (marks and block) can be used conjointly.
134 135 136 137 138 139 140 141 142 |
# File 'lib/yargi/element_set.rb', line 134 def add_marks(marks=nil) self.each {|elm| elm.add_marks(marks)} if marks if block_given? self.each do |elm| hash = yield elm elm.add_marks(hash) if Hash===hash end end end |
#compact ⇒ Object
See Array.compact
24 25 26 |
# File 'lib/yargi/element_set.rb', line 24 def compact() # :nodoc: # extend_result(super) end |
#concat(other) ⇒ Object
See Array.concat
49 50 51 |
# File 'lib/yargi/element_set.rb', line 49 def concat(other) # :nodoc: # extend_result(super(other)) end |
#dup ⇒ Object
Same as Array.dup
19 20 21 |
# File 'lib/yargi/element_set.rb', line 19 def dup() # :nodoc: # extend_result(super) end |
#each_cons(n) ⇒ Object
See Enumerable.each_cons
73 74 75 |
# File 'lib/yargi/element_set.rb', line 73 def each_cons(n) # :nodoc: # super(n) {|c| yield extend_result(c)} end |
#each_slice(n) ⇒ Object
See Enumerable.each_slice
78 79 80 |
# File 'lib/yargi/element_set.rb', line 78 def each_slice(n) # :nodoc: # super(n) {|c| yield extend_result(c)} end |
#filter(predicate = nil, &block) ⇒ Object
Filters this set with a ‘predicate and block’ predicate (see Yargi::Predicate)
150 151 152 153 |
# File 'lib/yargi/element_set.rb', line 150 def filter(predicate=nil, &block) pred = Yargi::Predicate.to_predicate(predicate, &block) extend_result(self.select{|e| pred===e}) end |
#find_all(&block) ⇒ Object
See Enumerable.find_all
88 89 90 |
# File 'lib/yargi/element_set.rb', line 88 def find_all(&block) # :nodoc: # extend_result(super(&block)) end |
#flatten ⇒ Object
See Array.flatten
29 30 31 |
# File 'lib/yargi/element_set.rb', line 29 def flatten() # :nodoc: # extend_result(super) end |
#get_mark(key) ⇒ Object
Collects result of get_mark invocation on each element of the group and returns it as an array.
119 120 121 |
# File 'lib/yargi/element_set.rb', line 119 def get_mark(key) self.collect {|elm| elm.get_mark(key)} end |
#grep(pattern, &block) ⇒ Object
See Enumerable.grep
93 94 95 96 |
# File 'lib/yargi/element_set.rb', line 93 def grep(pattern, &block) # :nodoc: # greped = super(pattern, &block) block_given? ? greped : extend_result(greped) end |
#partition(&block) ⇒ Object
See Enumerable.reject
99 100 101 102 |
# File 'lib/yargi/element_set.rb', line 99 def partition(&block) # :nodoc: # p = super(&block) [extend_result(p[0]), extend_result(p[1])] end |
#reject(&block) ⇒ Object
See Enumerable.reject
105 106 107 |
# File 'lib/yargi/element_set.rb', line 105 def reject(&block) # :nodoc: # extend_result(super(&block)) end |
#reverse ⇒ Object
See Array.reverse
34 35 36 |
# File 'lib/yargi/element_set.rb', line 34 def reverse() # :nodoc: # extend_result(super) end |
#select(&block) ⇒ Object
See Enumerable.select
83 84 85 |
# File 'lib/yargi/element_set.rb', line 83 def select(&block) # :nodoc: # extend_result(super(&block)) end |
#set_mark(key, value, dup = true) ⇒ Object
Fired to each element of the group. Values are duplicated by default. Put dup to false to avoid this behavior.
125 126 127 |
# File 'lib/yargi/element_set.rb', line 125 def set_mark(key, value, dup=true) self.each {|elm| elm.set_mark(key, (dup and not(Symbol===value)) ? value.dup : value)} end |
#sort(&block) ⇒ Object
See Array.sort
44 45 46 |
# File 'lib/yargi/element_set.rb', line 44 def sort(&block) # :nodoc: # extend_result(super(&block)) end |
#tag(*modules) ⇒ Object
Fired to each element of the group.
113 114 115 |
# File 'lib/yargi/element_set.rb', line 113 def tag(*modules) self.each {|elm| elm.tag(*modules)} end |
#uniq ⇒ Object
See Array.uniq
39 40 41 |
# File 'lib/yargi/element_set.rb', line 39 def uniq() # :nodoc: # extend_result(super) end |