Module: Wildcard

Defined in:
lib/like_structure/wildcard.rb

Defined Under Namespace

Classes: AnythingWildcard, TypeWildcard, Wildcard

Class Method Summary collapse

Class Method Details

.analyze_method_name(name) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/like_structure/wildcard.rb', line 39

def self.analyze_method_name(name)
  case name.to_s
  when /\Aany_(\w+)\Z/
    type_name = $1.capitalize
    return false unless Object.const_defined?(type_name)
    TypeWildcard.new(Object.const_get(type_name))
  else
    false
  end
end

.anythingObject



23
24
25
# File 'lib/like_structure/wildcard.rb', line 23

def self.anything
  AnythingWildcard.new(true)
end

.method_missing(name, *args, &block) ⇒ Object



35
36
37
# File 'lib/like_structure/wildcard.rb', line 35

def self.method_missing name, *args, &block
  args.empty? && block.nil? && analyze_method_name(name) or super
end

.not_nilObject



27
28
29
# File 'lib/like_structure/wildcard.rb', line 27

def self.not_nil
  AnythingWildcard.new(false)
end

.respond_to?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/like_structure/wildcard.rb', line 31

def self.respond_to? name, include_private = false
  analyze_method_name(name) ? true : super
end