Class: Mutant::Context::Scope
- Inherits:
-
Mutant::Context
- Object
- Mutant::Context
- Mutant::Context::Scope
- Includes:
- Adamantium::Flat
- Defined in:
- lib/mutant/context/scope.rb
Overview
Scope context for mutation (Class or Module)
Instance Attribute Summary collapse
-
#scope ⇒ ::Module|::Class
readonly
private
Return scope wrapped by context.
Attributes inherited from Mutant::Context
Class Method Summary collapse
-
.wrap(scope, node) ⇒ Rubinius::AST::Class, Rubinius::AST::Module
private
Wrap node into ast node.
Instance Method Summary collapse
-
#nesting ⇒ Enumerable<Class,Module>
private
Return nesting.
-
#root(node) ⇒ Rubinius::AST::Script
private
Return AST wrapping mutated node.
-
#unqualified_name ⇒ String
private
Return unqualified name of scope.
Instance Attribute Details
#scope ⇒ ::Module|::Class (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return scope wrapped by context
75 76 77 |
# File 'lib/mutant/context/scope.rb', line 75 def scope @scope end |
Class Method Details
.wrap(scope, node) ⇒ Rubinius::AST::Class, Rubinius::AST::Module
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Wrap node into ast node
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mutant/context/scope.rb', line 32 def self.wrap(scope, node) name = scope.name.split('::').last.to_sym case scope when ::Class ::Rubinius::AST::Class.new(0, name, nil, node) when ::Module ::Rubinius::AST::Module.new(0, name, node) else raise "Cannot wrap scope: #{scope.inspect}" end end |
Instance Method Details
#nesting ⇒ Enumerable<Class,Module>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return nesting
50 51 52 53 54 55 56 |
# File 'lib/mutant/context/scope.rb', line 50 def nesting const = ::Object name_nesting.each_with_object([]) do |name, nesting| const = const.const_get(name) nesting << const end end |
#root(node) ⇒ Rubinius::AST::Script
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return AST wrapping mutated node
13 14 15 16 17 |
# File 'lib/mutant/context/scope.rb', line 13 def root(node) nesting.reverse.inject(node) do |current, scope| self.class.wrap(scope, current) end end |
#unqualified_name ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return unqualified name of scope
65 66 67 |
# File 'lib/mutant/context/scope.rb', line 65 def unqualified_name name_nesting.last end |