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
| class A | |
| CONST_A = 1 | |
| @@a = 1 | |
| @b = 1 | |
| def self.get_a | |
| @@a | |
| end | |
| def self.get_b |
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
| a = true | |
| b = true | |
| if a && b | |
| puts "hoge" | |
| end | |
| if a and b | |
| puts "moge" | |
| end |
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
| a = 1.tap {|i| puts i + i} | |
| a # => 1 | |
| b = 1.tap {|i| break i + i} | |
| b # => 2 | |
| # >> 2 |
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
| # -*- encoding: utf-8 -*- | |
| a = 1 + 3 | |
| b = 5 + 4 | |
| c = a + b # => 13 | |
| d = c + b # => 22 | |
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/all' | |
| class A | |
| cattr_accessor :hoge | |
| class << self | |
| attr_accessor :moge | |
| end | |
| end | |
| class B < A; end |
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 'rmaybe' | |
| # This code returns "C" | |
| "a b c".split[2].upcase # => "C" | |
| # And if you use maybe. ... .end chain, you can get same result. | |
| "a b c".maybe.split[2].upcase.end # => "C" | |
| # This code causes NoMethodError. | |
| "a b c".split[3].upcase |
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
| def fib_iter(prev2, prev, remain) | |
| current = prev2 + prev | |
| remain > 0 ? fib_iter(prev, current, remain - 1) : current | |
| end | |
| # n == 0 => 0, n == 1 => 1, n == 2 => 1, n == 3 => 2, n == 4 => 3, n == 5 => 5 ... | |
| def fib(n) | |
| return n if [0, 1].include?(n) | |
| return fib_iter(0, 1, n - 2) | |
| end |
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
| # -*- encoding: utf-8 -*- | |
| old_csv = <<CSV | |
| 1,aaa | |
| 2,bbb | |
| 3,ccc | |
| 4,ddd | |
| CSV |
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
| # -*- encoding: utf-8 -*- | |
| require 'yaml' | |
| YAML::ENGINE.yamler= 'syck' | |
| require 'active_support/all' | |
| require 'json' | |
| json = '{"a":"\\u0000"}' | |
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
| # -*- encoding: utf-8 -*- | |
| require 'yaml' | |
| YAML::ENGINE.yamler= 'syck' | |
| require 'active_support/all' | |
| require 'json' | |
| json = '{"a":"\\u0000"}' | |