Я не могу понять, как я могу решить эту ошибку, так как метод действительно существует, я проверил его с помощью метода 'Hi'.
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> require 'tm'
=> true
irb(main):003:0> Tm.hi
Hey Tm here for duty!
=> nil
irb(main):004:0> hashfile = YAML.load_file('fr.yaml')
=> {"fr"=>{"colors"=>{"yellow"=>"Jaune", "white"=>"Blanc"}, "hello"=>"Bonjour"}}
irb(main):005:0> t = load_translation(hashfile)
Traceback (most recent call last):
2: from /Users/abderrahmane/.rbenv/versions/2.5.1/bin/irb:11:in `<main>'
1: from (irb):5 NoMethodError (undefined method `load_translation' for main:Object)
С моим классом:
class Tm
def self.hi
puts "Hey Tm here for duty!"
end
def auxload(hash, lang, concat='')
ans = {}
hash.each do |key, val|
if val.class == Hash
aux = auxload(val, lang, concat+key+'.')
aux.each do |k, v|
ans[k]=v
end
else
ans[concat+key]={lang => val}
end
end
return ans
end
# load the translation from the yaml files
def load_translation(hash)
key,value = hash.first
return auxload(value,key)
end
end