Class: ObjectInspector::Scope
- Inherits:
-
Object
- Object
- ObjectInspector::Scope
- Defined in:
- lib/object_inspector/scope.rb
Overview
ObjectInspector::Scope defines a predicate method that matches #name and responds with ‘true`. This is a prettier way to test for a given type of “scope” within objects.
Instance Attribute Summary collapse
-
#names ⇒ Array<#to_s>
The current value of names.
Instance Method Summary collapse
-
#initialize(names = %w[self])) ⇒ Scope
constructor
A new instance of Scope.
-
#join_flags(flags, separator: ObjectInspector.configuration.flags_separator) ⇒ Object
Join the passed-in flags with the passed in separator.
-
#join_info(items, separator: ObjectInspector.configuration.info_separator) ⇒ Object
Join the passed-in items with the passed in separator.
Constructor Details
#initialize(names = %w[self])) ⇒ Scope
Returns a new instance of Scope.
13 14 15 |
# File 'lib/object_inspector/scope.rb', line 13 def initialize(names = %w[self]) @names = Array(names).map { |name| String(name) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object (private)
37 38 39 40 41 42 43 44 |
# File 'lib/object_inspector/scope.rb', line 37 def method_missing(method_name, *args, &block) if method_name[-1] == "?" scope_name = method_name[0..-2] evaluate_match(scope_name, &block) else super end end |
Instance Attribute Details
#names ⇒ Array<#to_s>
Returns the current value of names.
10 11 12 |
# File 'lib/object_inspector/scope.rb', line 10 def names @names end |
Instance Method Details
#join_flags(flags, separator: ObjectInspector.configuration.flags_separator) ⇒ Object
Join the passed-in flags with the passed in separator.
21 22 23 24 |
# File 'lib/object_inspector/scope.rb', line 21 def join_flags(flags, separator: ObjectInspector.configuration.flags_separator) Array(flags).join(separator) end |
#join_info(items, separator: ObjectInspector.configuration.info_separator) ⇒ Object
Join the passed-in items with the passed in separator.
30 31 32 33 |
# File 'lib/object_inspector/scope.rb', line 30 def join_info(items, separator: ObjectInspector.configuration.info_separator) Array(items).join(separator) end |