我有一个哈希表,像这样:hash = {"band" => "for King & Country", "song_name" => "Matter"}
和一个类:
class Song
def initialize(*args, **kwargs)
#accept either just args or just kwargs
#initialize @band, @song_name
end
end
我想将hash
作为关键字参数传递,例如Song.new band: "for King & Country", song_name: "Matter"
。这是可能的吗?
hash = {band: "for King & Country", song_name: "Matter"}
。 - Stefan.yml
文件中获取hash
,这就是它返回的内容。 - mariya