This file contains 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
// Ruby 2.3.1 | |
/* eval.c:1614: */ rb_define_virtual_variable("$@", errat_getter, errat_setter); | |
/* eval.c:1615: */ rb_define_virtual_variable("$!", errinfo_getter, 0); | |
/* io.c:12280: */ rb_define_virtual_variable("$_", rb_lastline_get, rb_lastline_set); | |
/* load.c:1195: */ rb_define_virtual_variable("$\"", get_loaded_features, 0); | |
/* load.c:1196: */ rb_define_virtual_variable("$LOADED_FEATURES", get_loaded_features, 0); | |
/* process.c:7537: */ rb_define_virtual_variable("$?", rb_last_status_get, 0); | |
/* process.c:7538: */ rb_define_virtual_variable("$$", get_pid, 0); | |
/* re.c:3653: */ rb_define_virtual_variable("$~", match_getter, match_setter); | |
/* re.c:3654: */ rb_define_virtual_variable("$&", last_match_getter, 0); |
This file contains 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 Temperature | |
KelvinToCelsius = 273.15 | |
KelvinToFahrenheit = 459.67 | |
FahrenheitFactor = 5.0/9 | |
def self.from_kelvin(kelvin) # could just alias | |
new(k: kelvin) | |
end | |
def self.from_celsius(celsius) # IMO should be just named "celsius" |
This file contains 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 afaik mostly for assignment methods. e.g. `a.foo ||= b` expanding to `a.foo = a.foo || b` | |
would invoke foo= regardless of whether it's necessary. `a.foo || a.foo = b` would not. |
This file contains 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 Test::Unit::Assertions | |
def assert_unordered_equal(expected, actual, message=nil) | |
full_message = build_message(message, "<?> expected but was\n<?>.\n", expected, actual) | |
assert_block(full_message) { | |
seen = Hash.new(0) | |
expected.each { |e| seen[e] += 1 } | |
actual.each { |e| seen[e] -= 1 } | |
seen.invert.keys == [0] | |
} | |
end |
This file contains 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 Array | |
def split(*separator, include_separator: false) | |
if separator.empty? | |
if !block_given? | |
return enum_for(__method__) if separator.empty? && !block_given? | |
end | |
elsif block_given? | |
raise ArgumentError, "Must either pass a block or a separator, not both" | |
else | |
separator = separator.first |
This file contains 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 | |
# Column-Separator: | | |
# Record-Separator: auto | |
# Name: items | |
# Headers: true | |
ID | Name | Price | Inventory | |
1 | Watch | 2.99$ | 50 | |
2 | Table | 119.99$ | 12 | |
3 | Chair | 49.99$ | 19 |
This file contains 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
# Same result for the same IBM437 character - whether it's utf-8 or IBM437 encoded at input | |
JSON.parse(JSON.dump(["\u2561".encode('IBM437')])).first.unpack("U*") # => [9569] | |
JSON.parse(JSON.dump(["\u2561"])).first.unpack("U*") # => [9569] |
This file contains 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 | |
Column-Separator: 7c | |
Record-Separator: 0a | |
Name: items | |
Headers: true | |
"ID" | "Name" | "Price" | "Inventory" | |
1 | "Watch" | 2.99 | 50 | |
2 | "Table" | 119.99 | 12 |
This file contains 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 LayoutHelper | |
ActionMapping = { | |
'create' => 'new', | |
'update' => 'edit', | |
} | |
private | |
def rendered_action | |
@_rendered_action ||= begin |
This file contains 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 Enumerable | |
def compacting | |
return enum_for(__method__) unless block_given? | |
result = [] | |
each do |value| | |
next if value.nil? | |
result << value | |
yield(value) |