Skip to content

Instantly share code, notes, and snippets.

@kyohei-shimada
Last active March 26, 2018 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyohei-shimada/1da36465aae190230103af5db1c32fe6 to your computer and use it in GitHub Desktop.
Save kyohei-shimada/1da36465aae190230103af5db1c32fe6 to your computer and use it in GitHub Desktop.
require 'active_support'
require 'active_support/core_ext/hash/slice'
# キーを2つ指定したつもりが単なる文字列になってしまっていた...
{ 'key1' => 'hoge', 'key2' => 'fuga', 'key3' => 'piyo' }.slice(*" key1 key2 ")
#=> { }
This is a pen!
require 'active_support'
require 'active_support/core_ext/hash/slice'
{ 'key1' => 'hoge', 'key2' => 'fuga', 'key3' => 'piyo' }.slice(*%w( key1 key2 ))
#=> { "key1" => "hoge", "key2" => "fuga" }
require 'active_support'
require 'active_support/core_ext/hash/slice'
{ 'key1' => 'hoge', 'key2' => 'fuga', 'key3' => 'piyo' }.slice(%( key1 key2 ))
#=> { }
%w( a b c ) #=> ["a", "b", "c"]
%( a b c ) #=> " a b c "
x = %
This is a pen!
puts x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment