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
| o = Object.new | |
| def o.==(num) | |
| true | |
| end | |
| puts o == 42 | |
| puts [o].include?(42) | |
| puts [o].include?("a") | |
| puts [o].include?(nil) | |
| puts [o].include?(Object.new) |
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 'rubygems' | |
| require 'rspec' | |
| class Sequence | |
| def initialize(*elements) | |
| @elements = elements.sort | |
| end | |
| def elements | |
| @elements.dup |
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 Foo | |
| CONST = 42 | |
| end | |
| class Bar < Foo | |
| def self.foo | |
| CONST | |
| end | |
| class << self |
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 InfoDesk | |
| def trains | |
| :trains | |
| end | |
| def flights | |
| :flights | |
| end | |
| def buses | |
| :buses | |
| 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
| [branch] | |
| # git checkout foo automatically checks out origin/foo and names it foo and sets tracking branch. | |
| autosetupmerge = true | |
| # automatically set tracking branch to rebase instead of merge | |
| autosetuprebase = always | |
| [diff] | |
| # automatically detects renames | |
| renames = true | |
| [rebase] | |
| # automatically sets --autosquash when rebasing interactively |
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
| Wrong = Class.new(Exception) | |
| Right = Class.new(StandardError) | |
| begin | |
| raise Wrong, "Can't be rescued easily" | |
| rescue | |
| puts "Not reached" | |
| rescue Wrong | |
| puts "#{$!}, have to be explicitely rescued" | |
| 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
| module LocalMonkeyPatch | |
| def foo | |
| 42 | |
| end | |
| end | |
| array = [] | |
| array.extend LocalMonkeyPatch | |
| p array.foo |
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 Foo | |
| def foo(*args) | |
| puts(*args) | |
| end | |
| def bar | |
| foo = 42 | |
| foo foo | |
| end | |
| 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 'test/unit' | |
| class A | |
| def a | |
| end | |
| def method_missing(*) | |
| end | |
| end | |
| class B < A |
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
| # Using Array#assoc instead of a Hash when comparing using only == | |
| require 'test/unit/assertions' | |
| include Test::Unit::Assertions | |
| class Foo | |
| def initialize(i) | |
| @i = i | |
| end |
OlderNewer