Class: ObjectInspector::Scope

Inherits:
Object
  • Object
show all
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.

See Also:

  • http://api.rubyonrails.org/classes/ActiveSupport/StringInquirer.html

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#namesArray<#to_s>

Returns the current value of names.

Returns:

  • (Array<#to_s>)

    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.

Parameters:

  • items (Array<#to_s>)
  • separator (#to_s) (defaults to: ObjectInspector.configuration.flags_separator)

    (ObjectInspector.configuration.flags_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.

Parameters:

  • items (Array<#to_s>)
  • separator (#to_s) (defaults to: ObjectInspector.configuration.info_separator)

    (ObjectInspector.configuration.info_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