Module: Reality::Names

Defined in:
lib/reality/names.rb

Overview

This optional and higly experimental module allows treat ALL objects available with Reality, as Ruby constants (via redefined const_missing). This practice may seem questionable, so use it wisely!

You can just use this module on its own:

Reality::Names::Argentina
# => #<Reality::Entity(Argentina):country>

...Or just include it elsewhere:

include Reality::Names

Argentina
# => #<Reality::Entity(Argentina):country>

Multi-word entities can also be called:

BuenosAires
# => #<Reality::Entity(Buenos Aires):city>

Though, more complicated entity names (with punctuations) can't be accessed this way.

Class Method Summary collapse

Class Method Details

.const_missing(symbol) ⇒ Object



33
34
35
36
37
38
# File 'lib/reality/names.rb', line 33

def Names.const_missing(symbol)
  name = symbol.to_s.
    gsub('_', ' ').
    gsub(/([a-z])([A-Z])/, '\1 \2')
  Reality::Entity(name) or super
end