Class: RubyNext::Core::Patch
- Inherits:
-
Object
- Object
- RubyNext::Core::Patch
- Defined in:
- lib/ruby-next/core.rb
Overview
Patch contains the extension implementation and meta information (e.g., Ruby version).
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#core_ext ⇒ Object
readonly
Returns the value of attribute core_ext.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#mod ⇒ Object
readonly
Returns the value of attribute mod.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#native ⇒ Object
(also: #native?)
readonly
Returns the value of attribute native.
-
#refineables ⇒ Object
readonly
Returns the value of attribute refineables.
-
#singleton ⇒ Object
(also: #singleton?)
readonly
Returns the value of attribute singleton.
-
#supported ⇒ Object
(also: #supported?)
readonly
Returns the value of attribute supported.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #core_ext? ⇒ Boolean
-
#initialize(mod = nil, method:, version:, name: nil, supported: nil, native: nil, location: nil, refineable: mod, core_ext: :patch, singleton: nil) ⇒ Patch
constructor
Create a new patch for module/class (mod) with the specified uniq name.
- #prepend? ⇒ Boolean
- #to_module ⇒ Object
Constructor Details
#initialize(mod = nil, method:, version:, name: nil, supported: nil, native: nil, location: nil, refineable: mod, core_ext: :patch, singleton: nil) ⇒ Patch
Create a new patch for module/class (mod) with the specified uniq name
‘core_ext` defines the strategy for core extensions:
- :patch — extend class directly
- :prepend — extend class by prepending a module (e.g., when needs `super`)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby-next/core.rb', line 21 def initialize(mod = nil, method:, version:, name: nil, supported: nil, native: nil, location: nil, refineable: mod, core_ext: :patch, singleton: nil) @mod = mod @method_name = method @version = version if method_name && mod @supported = supported.nil? ? mod.method_defined?(method_name) : supported # define whether running Ruby has a native implementation for this method # for that, we check the source_location (which is nil for C defined methods) @native = native.nil? ? (supported? && native_location?(mod.instance_method(method_name).source_location)) : native end @singleton = singleton @refineables = Array(refineable) @body = yield @core_ext = core_ext @location = location || build_location(caller_locations(1, 5)) @name = name || build_module_name end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
13 14 15 |
# File 'lib/ruby-next/core.rb', line 13 def body @body end |
#core_ext ⇒ Object (readonly)
Returns the value of attribute core_ext.
13 14 15 |
# File 'lib/ruby-next/core.rb', line 13 def core_ext @core_ext end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
13 14 15 |
# File 'lib/ruby-next/core.rb', line 13 def location @location end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
13 14 15 |
# File 'lib/ruby-next/core.rb', line 13 def method_name @method_name end |
#mod ⇒ Object (readonly)
Returns the value of attribute mod.
13 14 15 |
# File 'lib/ruby-next/core.rb', line 13 def mod @mod end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/ruby-next/core.rb', line 13 def name @name end |
#native ⇒ Object (readonly) Also known as: native?
Returns the value of attribute native.
13 14 15 |
# File 'lib/ruby-next/core.rb', line 13 def native @native end |
#refineables ⇒ Object (readonly)
Returns the value of attribute refineables.
13 14 15 |
# File 'lib/ruby-next/core.rb', line 13 def refineables @refineables end |
#singleton ⇒ Object (readonly) Also known as: singleton?
Returns the value of attribute singleton.
13 14 15 |
# File 'lib/ruby-next/core.rb', line 13 def singleton @singleton end |
#supported ⇒ Object (readonly) Also known as: supported?
Returns the value of attribute supported.
13 14 15 |
# File 'lib/ruby-next/core.rb', line 13 def supported @supported end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
13 14 15 |
# File 'lib/ruby-next/core.rb', line 13 def version @version end |
Instance Method Details
#core_ext? ⇒ Boolean
43 44 45 |
# File 'lib/ruby-next/core.rb', line 43 def core_ext? !mod.nil? end |
#prepend? ⇒ Boolean
39 40 41 |
# File 'lib/ruby-next/core.rb', line 39 def prepend? core_ext == :prepend end |