Class: CodeWeb::MethodList
- Inherits:
-
Object
- Object
- CodeWeb::MethodList
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/code_web/method_list.rb
Instance Attribute Summary collapse
- #collection ⇒ Object
-
#name ⇒ Object
what was used in the group by.
Class Method Summary collapse
Instance Method Summary collapse
- #arg_keys ⇒ Object
- #detect(&block) ⇒ Object
- #each(&block) ⇒ Object
- #f ⇒ Object
- #group_by(name, arg_regex = nil, sort_by = nil, &block) ⇒ Object
-
#initialize(name, collection) ⇒ MethodList
constructor
A new instance of MethodList.
Constructor Details
#initialize(name, collection) ⇒ MethodList
Returns a new instance of MethodList.
13 14 15 16 |
# File 'lib/code_web/method_list.rb', line 13 def initialize(name, collection) @name = name @collection = collection end |
Instance Attribute Details
#collection ⇒ Object
11 12 13 |
# File 'lib/code_web/method_list.rb', line 11 def collection @collection end |
#name ⇒ Object
what was used in the group by
9 10 11 |
# File 'lib/code_web/method_list.rb', line 9 def name @name end |
Class Method Details
.group_by(collection, name) ⇒ Object
56 57 58 |
# File 'lib/code_web/method_list.rb', line 56 def self.group_by(collection, name) MethodList.new(nil, collection).group_by(name) end |
Instance Method Details
#arg_keys ⇒ Object
52 53 54 |
# File 'lib/code_web/method_list.rb', line 52 def arg_keys @arg_keys ||= collection.inject(Set.new) {|acc, m| m.arg_keys.each {|k| acc << k} ; acc}.sort_by {|n| n} end |
#detect(&block) ⇒ Object
42 43 44 |
# File 'lib/code_web/method_list.rb', line 42 def detect(&block) collection.detect(&block) end |
#each(&block) ⇒ Object
46 47 48 49 50 |
# File 'lib/code_web/method_list.rb', line 46 def each(&block) collection.each do |n, c| yield MethodList.new(n,c) end end |
#f ⇒ Object
35 36 37 |
# File 'lib/code_web/method_list.rb', line 35 def f collection.first end |
#group_by(name, arg_regex = nil, sort_by = nil, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/code_web/method_list.rb', line 18 def group_by(name, arg_regex=nil, sort_by = nil, &block) if block.nil? if arg_regex.nil? block = Proc.new { |m| m.send(name).to_s } else block = Proc.new {|m| if m.hash_args? m.hash_arg.collect {|n,v| v if n =~ arg_regex}.compact.join(" ") else m.signature end } end end MethodList.new(name, collection.group_by(&block).sort_by {|n, ms| sort_by ? ms.first.send(sort_by) : n }) end |