Last active
March 26, 2018 02:43
-
-
Save kyohei-shimada/1da36465aae190230103af5db1c32fe6 to your computer and use it in GitHub Desktop.
rubyの%記法にハマった ref: https://qiita.com/kyohei_shimada/items/07e4db87a2e01af33d1d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support' | |
require 'active_support/core_ext/hash/slice' | |
# キーを2つ指定したつもりが単なる文字列になってしまっていた... | |
{ 'key1' => 'hoge', 'key2' => 'fuga', 'key3' => 'piyo' }.slice(*" key1 key2 ") | |
#=> { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a pen! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support' | |
require 'active_support/core_ext/hash/slice' | |
{ 'key1' => 'hoge', 'key2' => 'fuga', 'key3' => 'piyo' }.slice(*%w( key1 key2 )) | |
#=> { "key1" => "hoge", "key2" => "fuga" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support' | |
require 'active_support/core_ext/hash/slice' | |
{ 'key1' => 'hoge', 'key2' => 'fuga', 'key3' => 'piyo' }.slice(%( key1 key2 )) | |
#=> { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%w( a b c ) #=> ["a", "b", "c"] | |
%( a b c ) #=> " a b c " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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