Class: ClassStructure
- Inherits:
-
Object
- Object
- ClassStructure
- Defined in:
- lib/class_structure.rb
Instance Method Summary collapse
- #collection_count ⇒ Object
- #has_accessor_method? ⇒ Boolean
-
#initialize(code) ⇒ ClassStructure
constructor
A new instance of ClassStructure.
- #instance_variables ⇒ Object
- #line_count ⇒ Object
- #method_names ⇒ Object
Constructor Details
#initialize(code) ⇒ ClassStructure
Returns a new instance of ClassStructure.
2 3 4 |
# File 'lib/class_structure.rb', line 2 def initialize(code) @code = code end |
Instance Method Details
#collection_count ⇒ Object
23 24 25 |
# File 'lib/class_structure.rb', line 23 def collection_count @code.scan(/\s+@\w+\s*\=\s*(\[.*?\]|\{.*?\}|Array\.new|Set\.new|Hash\.new)/).size end |
#has_accessor_method? ⇒ Boolean
14 15 16 17 |
# File 'lib/class_structure.rb', line 14 def has_accessor_method? all_instance_variables = instance_variables method_names.any? {|method_name| instance_variables.include?(method_name.gsub('=',''))} end |
#instance_variables ⇒ Object
6 7 8 |
# File 'lib/class_structure.rb', line 6 def instance_variables @code.scan(/\s+\@\w+/).map {|name| name.strip.sub('@','')}.uniq end |
#line_count ⇒ Object
19 20 21 |
# File 'lib/class_structure.rb', line 19 def line_count @code.split("\n").reject{|line| line.strip.size==0}.size end |
#method_names ⇒ Object
10 11 12 |
# File 'lib/class_structure.rb', line 10 def method_names @code.scan(/def \w+/).map {|name| name.sub('def ','')}.uniq end |