Class: AddedMethods::AddedMethod
- Inherits:
-
Object
- Object
- AddedMethods::AddedMethod
- Defined in:
- lib/added_methods/added_method.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.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #extract_source(num_lines = nil) ⇒ Object
-
#initialize(args = {}) ⇒ AddedMethod
constructor
A new instance of AddedMethod.
- #r2r_source ⇒ Object
- #source ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ AddedMethod
Returns a new instance of AddedMethod.
33 34 35 36 37 38 39 |
# File 'lib/added_methods/added_method.rb', line 33 def initialize(args = {}) self.time = Time.now args.each { |key, value| send("#{key}=", value) } end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
31 32 33 |
# File 'lib/added_methods/added_method.rb', line 31 def base @base end |
#def ⇒ Object
Returns the value of attribute def.
31 32 33 |
# File 'lib/added_methods/added_method.rb', line 31 def def @def end |
#file ⇒ Object
Returns the value of attribute file.
31 32 33 |
# File 'lib/added_methods/added_method.rb', line 31 def file @file end |
#klass ⇒ Object
Returns the value of attribute klass.
31 32 33 |
# File 'lib/added_methods/added_method.rb', line 31 def klass @klass end |
#line ⇒ Object
Returns the value of attribute line.
31 32 33 |
# File 'lib/added_methods/added_method.rb', line 31 def line @line end |
#name ⇒ Object
Returns the value of attribute name.
31 32 33 |
# File 'lib/added_methods/added_method.rb', line 31 def name @name end |
#singleton ⇒ Object Also known as: singleton?
Returns the value of attribute singleton.
31 32 33 |
# File 'lib/added_methods/added_method.rb', line 31 def singleton @singleton end |
#time ⇒ Object
Returns the value of attribute time.
31 32 33 |
# File 'lib/added_methods/added_method.rb', line 31 def time @time end |
Instance Method Details
#[](key) ⇒ Object
44 45 46 |
# File 'lib/added_methods/added_method.rb', line 44 def [](key) send(key.to_sym == :class ? :klass : key) end |
#extract_source(num_lines = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/added_methods/added_method.rb', line 56 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 if lines && lines.first =~ /\b#{name}\b/ lines else extract_source_from_r2r || lines end end |
#r2r_source ⇒ Object
52 53 54 |
# File 'lib/added_methods/added_method.rb', line 52 def r2r_source @r2r_source ||= extract_source_from_r2r end |
#source ⇒ Object
48 49 50 |
# File 'lib/added_methods/added_method.rb', line 48 def source @source ||= extract_source end |
#to_s ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/added_methods/added_method.rb', line 68 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 |