forked from franzejr/best-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add expected outputs when running files.
I used following command to help me so I didn't have to run each file manually and append the append to the source: ``` find . -iname '*.rb' -exec sh -c 'echo "\n# Result:" >> {}; gtimeout 2 ruby {} 2>&1 | sed "s/^/# /" >> {}' \; ```
- Loading branch information
1 parent
3e80f98
commit 2c2ef46
Showing
30 changed files
with
147 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 |
---|---|---|
|
@@ -3,3 +3,7 @@ | |
|
||
p aa.assoc("Someone") | ||
p aa.assoc("Bla") | ||
|
||
# Result: | ||
# ["Someone", "1"] | ||
# ["Bla", "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 |
---|---|---|
|
@@ -3,3 +3,6 @@ | |
|
||
deep[:a][:b][:c][:d] = 42 | ||
p deep | ||
|
||
# Result: | ||
# {:a=>{:b=>{:c=>{:d=>42}}}} |
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 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 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 |
---|---|---|
|
@@ -9,3 +9,7 @@ | |
when 65..Float::INFINITY | ||
p 'You are too old' | ||
end | ||
|
||
# Result: | ||
# 55 | ||
# "You are at the right age" |
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 |
---|---|---|
@@ -1,3 +1,23 @@ | ||
require 'pp' | ||
|
||
pp ObjectSpace.count_objects | ||
|
||
# Result: | ||
# {:TOTAL=>30163, | ||
# :FREE=>1007, | ||
# :T_OBJECT=>39, | ||
# :T_CLASS=>534, | ||
# :T_MODULE=>24, | ||
# :T_FLOAT=>4, | ||
# :T_STRING=>9290, | ||
# :T_REGEXP=>70, | ||
# :T_ARRAY=>2231, | ||
# :T_HASH=>53, | ||
# :T_STRUCT=>1, | ||
# :T_BIGNUM=>2, | ||
# :T_FILE=>14, | ||
# :T_DATA=>966, | ||
# :T_MATCH=>1, | ||
# :T_COMPLEX=>1, | ||
# :T_NODE=>15896, | ||
# :T_ICLASS=>30} |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
ring = %w[one two three].cycle | ||
|
||
p ring.take(5) | ||
|
||
# Result: | ||
# ["one", "two", "three", "one", "two"] |
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 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 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 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 |
---|---|---|
|
@@ -4,3 +4,6 @@ | |
|
||
|
||
p fibonacci[300] | ||
|
||
# Result: | ||
# 222232244629420445529739893461909967206666939096499764990979600 |
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 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 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 |
---|---|---|
@@ -1,2 +1,14 @@ | ||
p (1..10).inject{ |r,e| p [r,e]; r*2} | ||
|
||
|
||
# Result: | ||
# [1, 2] | ||
# [2, 3] | ||
# [4, 4] | ||
# [8, 5] | ||
# [16, 6] | ||
# [32, 7] | ||
# [64, 8] | ||
# [128, 9] | ||
# [256, 10] | ||
# 512 |
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
ObjectSpace.each_object(String) do |object| | ||
p object | ||
end | ||
|
||
# Result: | ||
# "block in dependent_specs" | ||
# "block in dependent_specs" | ||
# "block (3 levels) in dependent_gems" | ||
# "block (3 levels) in dependent_gems" | ||
# ... (huge output suppressed) | ||
# "This rdoc is bundled with 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 |
---|---|---|
|
@@ -6,3 +6,6 @@ module Kernel | |
|
||
l = λ { p :called } | ||
l.call | ||
|
||
# Result: | ||
# :called |
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 |
---|---|---|
|
@@ -4,3 +4,5 @@ def debug(name, content) | |
|
||
debug "Num", 42 | ||
|
||
# Result: | ||
# "Num: 42" |
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 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 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 |
---|---|---|
|
@@ -6,3 +6,6 @@ def full | |
|
||
franzejr = Struct::Name.new("Franze", "Jr") | ||
p franzejr.full | ||
|
||
# Result: | ||
# "Franze Jr" |
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 |
---|---|---|
|
@@ -11,3 +11,6 @@ def show_args(a,b,c) | |
end | ||
|
||
Child.new.show_args(:a, :b, :c) | ||
|
||
# Result: | ||
# [: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
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 |
---|---|---|
|
@@ -13,3 +13,6 @@ def show_args(a,b,c) | |
|
||
#Nothing goes up | ||
Child.new.show_args(:a, :b, :c) | ||
|
||
# Result: | ||
# [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
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 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 |
---|---|---|
|
@@ -12,3 +12,5 @@ def factorial(n, result=1) | |
end | ||
|
||
p factorial(100000) | ||
|
||
# Result: |
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 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 |
---|---|---|
|
@@ -5,3 +5,8 @@ | |
].each do |name,_,_| | ||
p name | ||
end | ||
|
||
# Result: | ||
# "Someone" | ||
# "Someone2" | ||
# "Someone3" |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
if /\A(?<first>\w+),\s*(?<last>\w+)\z/ =~ "Franze, Jr" | ||
puts "#{first} #{last}" | ||
end | ||
|
||
# Result: | ||
# Franze Jr |
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