Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add console presentation on ruby 2.4 new features
- Loading branch information
1 parent
e9f18f5
commit 047d8a8
Showing
75 changed files
with
407 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p !!/foo/.match("foo") | ||
p !!"foo".match(/foo/) | ||
p !!:foo.match(/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Thread.new do | ||
begin | ||
raise 'foo' | ||
rescue Exception => e | ||
puts "#{Thread.current} terminated with exception:" | ||
puts "#{e.backtrace.first}: #{e.message} (#{e.class})" | ||
end | ||
end | ||
sleep 0.01 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'irb' | ||
IRB.setup(eval("__FILE__")) | ||
irb = IRB::Irb.new(IRB::WorkSpace.new(binding)) | ||
IRB.conf[:MAIN_CONTEXT] = irb.context | ||
irb.eval_input |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
p Integer.equal?(Integer) | ||
p Integer.equal?(Integer) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# No equivalent | ||
s = "\u00EB\u00C4\u00D6" | ||
p s | ||
p s.upcase | ||
p s.downcase | ||
p s.swapcase | ||
p s.capitalize |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
if (a, b = [1, 2]; [1,2]) | ||
p a | ||
p b | ||
end | ||
unless (a, b = nil; nil) | ||
p a | ||
p b | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Foo | ||
refine String do | ||
def a; 1; end | ||
end | ||
end | ||
|
||
using Foo | ||
meth = :a | ||
eval <<END | ||
using Foo | ||
p 'a'.#{meth} | ||
p 'ab'.each_char.map{|s| s.#{meth}} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
puts ((raise rescue 1)) | ||
begin | ||
eval('puts(raise rescue 1)') | ||
rescue SyntaxError | ||
puts "Still Bad" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
p 1 | ||
if false | ||
p 2 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# No equivalent | ||
o = Object.new | ||
def o.foo; 1 end | ||
o.freeze | ||
|
||
begin | ||
x = o.clone | ||
def x.bar; foo + 2 end | ||
p x.bar | ||
rescue | ||
p $! | ||
end | ||
|
||
begin | ||
x = o.dup | ||
def x.bar; foo + 2 end | ||
x.freeze | ||
p x.bar | ||
rescue | ||
p $! | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# No equivalent | ||
$VERBOSE = true | ||
instance_variable_get(:@foo) | ||
$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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
p (1...100).inject(0, :+) | ||
p (1...100).to_a.inject(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
s = StringIO.new <<END | ||
a | ||
b | ||
a | ||
c | ||
END | ||
p s.each_line.to_a.uniq |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
p File.zero?(__FILE__) | ||
p Dir.new(__dir__).entries.length == 2 | ||
require 'pathname' | ||
p File.zero?(Pathname.new(__FILE__).to_s) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
m = 'food'.match(/(?<a>.)(?<b>..)(?<c>.)/) | ||
p m.names.inject({}){|a, n| a[n] = m[n]; a} | ||
p [:a, :b, :c].map{|c| m[c]} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p 1234.to_s.split(//).reverse.map(&:to_i) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
f = 12.35678 | ||
p((f*(10**1)).ceil/(10.0**1)) | ||
p((f*(10**2)).floor/(10.0**2)) | ||
p((f*(10**3)).round/(10.0**3)) | ||
p((f*(10**4)).truncate/(10.0**4)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
f = 12.5 | ||
p ((f.round - f == 0.5) ? (f.round.odd? ? f.round - 1 : f.round) : f.round) | ||
p f.round | ||
p ((f.round - f == 0.5) ? f.round - 1 : f.round) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p :foo.to_s.match(/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p [3].concat([1]).concat([2]) | ||
p "foo".concat("bar").concat("baz") | ||
p "foo".prepend("baz").prepend("bar") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p 1 < 3 ? 3 : (1 > 5 ? 5 : 1) | ||
p 4 < 3 ? 3 : (4 > 5 ? 5 : 4) | ||
p 7 < 3 ? 3 : (7 > 5 ? 5 : 7) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p({a: 1, b: nil}.inject({}){|a, (k,v)| a[k] = v unless v.nil?; 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p({a: 1, b: nil}.inject({}){|a, (k,v)| a[k] = !v; 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
File.open('runner.rb').each_line{|l| p l.chomp; break} | ||
StringIO.new("a\nb\n").each_line{|l| p l.chomp} | ||
"a\nb\n".each_line{|l| p l.chomp} | ||
p "a\nb\n".lines.map(&:chomp) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# No equivalent | ||
module Foo | ||
refine Enumerable do | ||
def a; 1 end | ||
end | ||
end | ||
|
||
using Foo | ||
p [].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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# No equivalent | ||
module Foo | ||
refine String do | ||
def a; 1 end | ||
end | ||
end | ||
|
||
p Module.used_modules | ||
using Foo | ||
p Module.used_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p "\x10\x00".unpack('s').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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
s = ''.b | ||
s.replace([1].pack('s')) | ||
p s |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
p ((x = 'foo'.casecmp('Foo')).is_a?(Integer) ? x.zero? : x) | ||
p ((x = :foo.casecmp(:Bar)).is_a?(Integer) ? x.zero? : x) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'net/http' | ||
require 'uri' | ||
url = URI('http://localhost/') | ||
Net::HTTP.start(url.hostname, url.port) do |http| | ||
http.post(url.path, "q" => "ruby") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# No built-in equivalent | ||
require 'double_bag_ftps' | ||
ftp = DoubleBagFTPS.new | ||
ftp.connect('localhost') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p TRUE | ||
p FALSE | ||
p NIL |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'logger' | ||
logger = Logger.new($stderr) | ||
logger.level = :info | ||
logger.progname = 'L2' | ||
logger.info '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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'optparse' | ||
h = {} | ||
OptionParser.new do |o| | ||
o.on "-f", "--foo=HOST" do |v| | ||
h[:foo] = v | ||
end | ||
o.on "-b", "--bar=PORT", Integer do |v| | ||
h[:bar] = v | ||
end | ||
o.on "-B", "--baz" do | ||
h[:baz] = true | ||
end | ||
end.parse(%w'-f FOO --bar 3 -B') | ||
p h |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p (10.0**400) < Float::MIN ? -1 : ((10.0**400) > Float::MAX ? 1: true) | ||
p -(10.0**400) < Float::MIN ? -1 : (-(10.0**400) > Float::MAX ? 1: true) | ||
p 1.0 < Float::MIN ? -1 : (1.0 > Float::MAX ? 1: true) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# No equivalent | ||
p String.new |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p /foo/.match?("foo") | ||
p "foo".match?(/foo/) | ||
p :foo.match?(/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Thread.new do | ||
Thread.current.report_on_exception = true | ||
raise 'foo' | ||
end | ||
sleep 0.01 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'irb' | ||
binding.irb |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
p Fixnum.equal?(Integer) | ||
p Bignum.equal?(Integer) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
s = "\u00EB\u00C4\u00D6" | ||
p s | ||
p s.upcase | ||
p s.downcase | ||
p s.swapcase | ||
p s.capitalize |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
if (a, b = [1, 2]) | ||
p a | ||
p b | ||
end | ||
unless (a, b = nil) | ||
p a | ||
p b | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Foo | ||
refine String do | ||
def a; 1; end | ||
end | ||
end | ||
|
||
using Foo | ||
meth = :a | ||
p 'a'.send(meth) | ||
p 'ab'.each_char.map(&meth) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
puts (raise rescue 1) | ||
begin | ||
eval('puts(raise rescue 1)') | ||
rescue SyntaxError | ||
puts "Still Bad" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p 1 | ||
return | ||
p 2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
o = Object.new | ||
def o.foo; 1 end | ||
o.freeze | ||
x = o.clone(freeze: false) | ||
def x.bar; foo + 2 end | ||
x.freeze | ||
p x.bar |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$VERBOSE = true | ||
def Warning.warn(s) | ||
puts "WARNING: #{s}" unless s =~ /instance variable @.+ not initialized/ | ||
end | ||
instance_variable_get(:@foo) | ||
$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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
p (1...100).sum | ||
p (1...100).to_a.sum |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
s = StringIO.new <<END | ||
a | ||
b | ||
a | ||
c | ||
END | ||
p s.each_line.uniq |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
p File.empty?(__FILE__) | ||
p Dir.empty?(__dir__) | ||
require 'pathname' | ||
p Pathname.new(__FILE__).empty? |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
m = 'food'.match(/(?<a>.)(?<b>..)(?<c>.)/) | ||
p m.named_captures | ||
p m.values_at(:a, :b, :c) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p 1234.digits |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
f = 12.35678 | ||
p f.ceil(1) | ||
p f.floor(2) | ||
p f.round(3) | ||
p f.truncate(4) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
f = 12.5 | ||
p f.round(half: :even) | ||
p f.round(half: :up) | ||
p f.round(half: :down) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p :foo.match(/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p [3].concat([1], [2]) | ||
p "foo".concat("bar", "baz") | ||
p "foo".prepend("bar", "baz") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p 1.clamp(3, 5) | ||
p 4.clamp(3, 5) | ||
p 7.clamp(3, 5) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p({a: 1, b: nil}.compact) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p({a: 1, b: nil}.transform_values{|v| !v}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
File.open('runner.rb').each_line(chomp: true){|l| p l; break} | ||
StringIO.new("a\nb\n").each_line(chomp: true){|l| p l} | ||
"a\nb\n".each_line(chomp: true){|l| p l} | ||
p "a\nb\n".lines(chomp: true) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Foo | ||
refine Enumerable do | ||
def a; 1 end | ||
end | ||
end | ||
|
||
using Foo | ||
p [].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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Foo | ||
refine String do | ||
def a; 1 end | ||
end | ||
end | ||
|
||
p Module.used_modules | ||
using Foo | ||
p Module.used_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p "\x10\x00".unpack1('s') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
s = ''.b | ||
[1].pack('s', :buffer=>s) | ||
p s |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
p 'foo'.casecmp?('Foo') | ||
p :foo.casecmp?(:Bar) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'net/http' | ||
require 'uri' | ||
Net::HTTP.post(URI('http://localhost/'), {"q" => "ruby"}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'net/ftp' | ||
ftp = Net::FTP.new('localhost', :ssl=>true) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p TRUE | ||
p FALSE | ||
p NIL |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'logger' | ||
logger = Logger.new($stderr, level: :info, progname: "L2") | ||
logger.info '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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'optparse' | ||
h = {} | ||
OptionParser.new do |o| | ||
o.on "-f", "--foo=HOST" | ||
o.on "-b", "--bar=PORT", Integer | ||
o.on "-B", "--baz" | ||
end.parse(%w'-f FOO --bar 3 -B', :into=>h) | ||
p h |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p (10.0**400).infinite? | ||
p (-(10.0**400)).infinite? | ||
p (1.0).finite? |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p String.new(:capacity=>1 << 30) |
Oops, something went wrong.