Class: Util::AddedMethods::AddedMethod
- Defined in:
- lib/nuggets/util/added_methods.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#def ⇒ Object
Returns the value of attribute def.
-
#file ⇒ Object
Returns the value of attribute file.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#line ⇒ Object
Returns the value of attribute line.
-
#name ⇒ Object
Returns the value of attribute name.
-
#singleton ⇒ Object
(also: #singleton?)
Returns the value of attribute singleton.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #extract_source(num_lines = nil) ⇒ Object
-
#initialize(args = {}) ⇒ AddedMethod
constructor
A new instance of AddedMethod.
- #source ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ AddedMethod
Returns a new instance of AddedMethod.
79 80 81 82 83 |
# File 'lib/nuggets/util/added_methods.rb', line 79 def initialize(args = {}) args.each { |key, value| send("#{key}=", value) } end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
77 78 79 |
# File 'lib/nuggets/util/added_methods.rb', line 77 def base @base end |
#def ⇒ Object
Returns the value of attribute def.
77 78 79 |
# File 'lib/nuggets/util/added_methods.rb', line 77 def def @def end |
#file ⇒ Object
Returns the value of attribute file.
77 78 79 |
# File 'lib/nuggets/util/added_methods.rb', line 77 def file @file end |
#klass ⇒ Object
Returns the value of attribute klass.
77 78 79 |
# File 'lib/nuggets/util/added_methods.rb', line 77 def klass @klass end |
#line ⇒ Object
Returns the value of attribute line.
77 78 79 |
# File 'lib/nuggets/util/added_methods.rb', line 77 def line @line end |
#name ⇒ Object
Returns the value of attribute name.
77 78 79 |
# File 'lib/nuggets/util/added_methods.rb', line 77 def name @name end |
#singleton ⇒ Object Also known as: singleton?
Returns the value of attribute singleton.
77 78 79 |
# File 'lib/nuggets/util/added_methods.rb', line 77 def singleton @singleton end |
Instance Method Details
#[](key) ⇒ Object
88 89 90 |
# File 'lib/nuggets/util/added_methods.rb', line 88 def [](key) send(key.to_sym == :class ? :klass : key) end |
#extract_source(num_lines = nil) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/nuggets/util/added_methods.rb', line 96 def extract_source(num_lines = nil) lines = extract_source_from_script_lines(num_lines) # try to make sure we correctly extracted the method # definition, otherwise try to get it from Ruby2Ruby lines.first =~ /\b#{name}\b/ ? lines : extract_source_from_r2r || lines end |
#source ⇒ Object
92 93 94 |
# File 'lib/nuggets/util/added_methods.rb', line 92 def source @source ||= extract_source end |
#to_s ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/nuggets/util/added_methods.rb', line 104 def to_s str = "# File #{file}, line #{line}" case lines = source when Array num = line - 1 width = (num + lines.size).to_s.length lines.map! { |l| "%0#{width}d: %s" % [num += 1, l] } "#{' ' * width} #{str}\n#{lines}" when String "#{str}#{lines}" else str end end |