module Russial::Dictionary::DynamicMethods
Constants
- Key
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/russial/dictionary/dynamic_methods.rb, line 5 def initialize(*) super generate_methods generate_aliases initialize_defaults end
Private Instance Methods
extract_keys(hash, scope = [])
click to toggle source
# File lib/russial/dictionary/dynamic_methods.rb, line 56 def extract_keys(hash, scope = []) hash.map do |k, v| if v.is_a? Hash extract_keys(v, scope + [k]) << Key.new(k, scope) else [Key.new(k, scope)] end end end
generate_aliases()
click to toggle source
# File lib/russial/dictionary/dynamic_methods.rb, line 24 def generate_aliases singleton_class.class_eval do superclass.config.aliases.each do |a, m| begin alias_method a, m rescue NameError next end end end end
generate_methods()
click to toggle source
# File lib/russial/dictionary/dynamic_methods.rb, line 14 def generate_methods keys.each do |key| name = key.name define_singleton_method(name) do path << name unless path.include? name get end end end
get()
click to toggle source
# File lib/russial/dictionary/dynamic_methods.rb, line 36 def get case (memoized_result = result) when Hash self when String soft_reset_path substitutions.empty? ? memoized_result : substitute(memoized_result) end end
keys()
click to toggle source
# File lib/russial/dictionary/dynamic_methods.rb, line 52 def keys @keys ||= extract_keys(dictionary).flatten end
substitute(word)
click to toggle source
# File lib/russial/dictionary/dynamic_methods.rb, line 46 def substitute(word) substitutions.inject(word) do |result, (from, to)| result.gsub(from.to_s, to) end end