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
def foo | |
:foo | |
end | |
def bar(foo = 1) | |
p foo #=> 1(2.1.1, 2.2.0) | |
end | |
def hoge(foo = foo) | |
p foo #=> :foo(2.1.1), nil(2.2.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
require 'power_assert' | |
module RSpec | |
module PowerAssert | |
def power_assert(&block) | |
::PowerAssert.start(block) do |pa| | |
ret = pa.yield | |
unless ret | |
raise RSpec::Expectations::ExpectationNotMetError, "\nPowerAssert:\n#{pa.message_proc.call}" | |
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
RSpec.configure do |config| | |
config.mock_with :rspec | |
end | |
class PriceCalc | |
def initialize(order) | |
@order = order | |
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
Pq"1;1;486;516#0;2;97;97;97#1;2;97;97;94#2;2;94;91;91#3;2;94;88;88#4;2;91;85;85#5;2;91;82;82#6;2;85;69;69#7;2;78;60;60#8;2;78;56;56#9;2;75;56;56#10;2;82;63;63#11;2;88;75;75#12;2;85;72;72#13;2;88;78;78#14;2;82;66;66#15;2;97;94;94#16;2;94;94;94#17;2;78;78;78#18;2;63;63;63#19;2;47;47;47#20;2;85;85;85#21;2;66;66;66#22;2;28;28;28#23;2;31;31;31#24;2;38;38;38#25;2;75;75;75#26;2;91;91;91#27;2;88;88;88#28;2;41;41;41#29;2;69;69;69#30;2;72;72;72#0~~z!7~|!14~z!7~}!15~v!23~|!412~$#1??C!7?A!14?C!7?@!15?G!23?A-#0~~|!483~$#1??A-#0!486~-!17~}}!467~$#1!17?@@-#0!108~z!377~$#1!108?C-#0!486~-!486~-!486~-!486~-!242~^^NFFBB@@@#3??@#10?___?__??A#11A???G#6?O??_$#1!242?_!9?@#14!6?_#0!4?@@@BBFFNNN^^^!209~$#6!243?_??G?C??A#12!15?C#5!4?O??_$#8!244?__?G?C_?ccQOQ!4?AOAC?K?O?_?__$#13!244?O#2G???A???@!9?@??A?C?G??O??_$#7!245?OO?G?CcAA__?!4QO_?_C?GGOO_$#9!246?_oow!4WKM!6KM{Wwoo__$#4!247?C!7?@!6?@$#5!250?A!5?!6@-#0!237~NFB@!4?_ow{{}}}!10~}}{{wwwooo__???@B^!205~$#6!237?_!4?@!4?C???@#2!11?@?A#7@?A?CCG?H@@AG_#2_$#1!237?O#7_OKCA`??CAA@@#6!13?@?A? |
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 DartsLive | |
def self.rating(zero_one_stats, cricket_stats) | |
((0.2 * zero_one_stats - 6) + (5.0 * cricket_stats - 4.5)) / 2 | |
end | |
module NumericExtension | |
def need_stats | |
{:zero_one => (self + 6) / 0.2, :cricket => (self + 4.5) / 5} | |
end | |
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 Foo | |
def class_object | |
self.class.to_s.split(/::/).inject(Object) do |c, name| | |
c.const_get(name) | |
end | |
end | |
end | |
Foo.new.class_object #=> Foo |
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 quicksort! | |
return self if self.size <= 1 | |
piv = self[0] | |
top, bottom = self[1..-1].partition{|i| i < piv} | |
top.quicksort + [piv] + bottom.quicksort | |
end | |
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
"A".upto "Z" do |c| | |
puts c | |
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
module Enumerable | |
def bubblesort! | |
return self if self.size <= 1 | |
(self.size - 1).downto(0) do |i| | |
0.upto(i - 1) do |j| | |
self[j+1], self[j] = self[j], self[j+1] if self[j] > self[j+1] | |
end | |
end | |
self |
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
BEGIN { | |
$a = 10 | |
puts "begin1 #{$a}" | |
} | |
BEGIN { | |
$a = 20 | |
puts "begin2 #{$a}" | |
} |
OlderNewer