###Rails在Controller中使用helper方法
view_context.link_to "link", "http://www.baidu.com" or ActionController::Base.helpers.link_to "link", "http://www.baidu.com"
each_with_object
###old_hash.each_with_object(初期化object) {|item, new_hash| block処理 } smile = { vocal:'tim', guitar:'brian', bass:'tim', drum:'roger' } queen = smile.each_with_object({}) do |(key, val), member| member[key.to_sym] = case key when :vocal member[:vocal] = 'fleddie' when :bass member[:bass] = 'jhon' else val end end
inject
###old_hash.inject(初期化object) {|new_hash, item| block処理 } smile = { vocal:'tim', guitar:'brian', bass:'tim', drum:'roger' } queen = smile.inject({}) do |member, (key, val)| member[key.to_sym] = case key when :vocal member[:vocal] = 'fleddie' when :bass member[:bass] = 'jhon' else val end member #injectの場合、ブロックでループする最後に作成中のhashを返す行が必要 end
标签:hash,bass,小结,object,rails,member,vocal,key,方法 From: https://www.cnblogs.com/hello-ruby/p/17424453.html