-1
ルビのメソッドから匿名オブジェクトを返すにはどうしたらいいですか?ルビのメソッドから匿名オブジェクトを返します
次のコードでは、ハッシュを返しています。
def process
source = helper
# I am able to get the value as an hash
puts source[:url]
puts source[:params]
# But I wonder if there is a way to get it as an object, so that I can use the dot notation
# puts source.url
# puts source.params
end
def helper
url = ''
params = ''
return {url: url, params: params}
end
任意の考え。
あなたの質問は不明です。 Rubyのオブジェクトには名前はなく、常に匿名です。あなたのコードでは、匿名のオブジェクト、つまり 'ハッシュ'を返しています。 –