Add 'RubyFun/' from commit 'b01c6826131196ba58b5288a3182f2526c89c249'
git-subtree-dir: RubyFun git-subtree-mainline:a04a502787
git-subtree-split:b01c682613
This commit is contained in:
8
RubyFun/round0/blocks.rb
Normal file
8
RubyFun/round0/blocks.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
# read file and write to archive
|
||||
File.open("archive.log", "a") do |saved|
|
||||
File.foreach("mylogfile.log") do |sending|
|
||||
puts("data = #{sending}")
|
||||
# Make sure we keep a backup
|
||||
saved.puts(sending) # removed superfluous string interpolation
|
||||
end
|
||||
end
|
19
RubyFun/round0/fact.rb
Normal file
19
RubyFun/round0/fact.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# factorializer!
|
||||
|
||||
def fact(n)
|
||||
if n == 0
|
||||
return 1
|
||||
else
|
||||
return n * fact(n - 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def main()
|
||||
puts fact(ARGV[0].to_i)
|
||||
end
|
||||
|
||||
|
||||
if __FILE__ == $0
|
||||
main()
|
||||
end
|
31
RubyFun/round0/hello.rb
Normal file
31
RubyFun/round0/hello.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
=begin
|
||||
|
||||
OMG this be my comment
|
||||
|
||||
|
||||
=end
|
||||
|
||||
|
||||
class Greeter
|
||||
def initialize(name="World")
|
||||
@name = name
|
||||
end
|
||||
def say_hi
|
||||
puts "Hi #{@name}!"
|
||||
end
|
||||
def say_bye
|
||||
puts "Bye #{@name}, y'all come back now."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def main
|
||||
grt = Greeter.new("Fizzle")
|
||||
grt.say_hi()
|
||||
grt.say_bye()
|
||||
end
|
||||
|
||||
|
||||
if __FILE__ == $0
|
||||
main()
|
||||
end
|
15
RubyFun/round0/metherds.rb
Normal file
15
RubyFun/round0/metherds.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
def main()
|
||||
5.times { puts "Mice!\n" }
|
||||
|
||||
ele = "Elephants like Peanuts, but they is poison!!"
|
||||
|
||||
puts ele + ' is of length = ' + ele.length.to_s
|
||||
|
||||
puts "I yam: " + self.to_s
|
||||
|
||||
end
|
||||
|
||||
|
||||
if __FILE__ == $0
|
||||
main()
|
||||
end
|
27
RubyFun/round0/mydefs.rb
Normal file
27
RubyFun/round0/mydefs.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
def hello()
|
||||
puts 'Hello!'
|
||||
end
|
||||
|
||||
|
||||
def hello_to(name)
|
||||
puts 'Hello thar ' + name.to_s
|
||||
end
|
||||
|
||||
|
||||
def hello_again_to name
|
||||
puts 'Why hello again ' + name.to_s
|
||||
end
|
||||
|
||||
|
||||
def main()
|
||||
puts 'your name be? '
|
||||
name = gets().chomp()
|
||||
hello()
|
||||
hello_to(name)
|
||||
hello_again_to(name)
|
||||
end
|
||||
|
||||
|
||||
if __FILE__ == $0
|
||||
main()
|
||||
end
|
1
RubyFun/round0/mypid.rb
Normal file
1
RubyFun/round0/mypid.rb
Normal file
@@ -0,0 +1 @@
|
||||
puts $$
|
2
RubyFun/round0/nums.rb
Normal file
2
RubyFun/round0/nums.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
puts 'dig = ' + (Float::DIG).to_s
|
||||
puts 'float = ' + (Float::MAX).to_s
|
6
RubyFun/round0/pipes.rb
Normal file
6
RubyFun/round0/pipes.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
puts `ls -l .`
|
||||
puts 'we be in ' + `pwd`
|
||||
|
||||
puts system('hostname -a')
|
14
RubyFun/round0/question.rb
Normal file
14
RubyFun/round0/question.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
def has_a_flavor?()
|
||||
puts 'pick a number'
|
||||
num = gets().chomp().to_i
|
||||
if num % 2 != 0
|
||||
puts 'NO'
|
||||
else
|
||||
puts 'YAS'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if __FILE__ == $0
|
||||
has_a_flavor?()
|
||||
end
|
6
RubyFun/round0/rice.rb
Normal file
6
RubyFun/round0/rice.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
rice_on_square = 1
|
||||
|
||||
64.times do |square|
|
||||
puts "On square #{square + 1} are #{rice_on_square} grain(s)"
|
||||
rice_on_square *= 2
|
||||
end
|
1
RubyFun/round0/search_path.rb
Normal file
1
RubyFun/round0/search_path.rb
Normal file
@@ -0,0 +1 @@
|
||||
puts $:
|
11
RubyFun/round0/strang.rb
Normal file
11
RubyFun/round0/strang.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
foo = <<EOS
|
||||
this be my crazy
|
||||
big
|
||||
multiline
|
||||
string
|
||||
EOS
|
||||
|
||||
puts foo
|
||||
|
||||
nums = "20000.0030300"
|
||||
puts nums.to_f
|
4
RubyFun/round0/streams.rb
Normal file
4
RubyFun/round0/streams.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
puts 'where do ye live?'
|
||||
STDOUT.flush()
|
||||
city = gets.chomp()
|
||||
puts 'yar city be ' + city
|
17
RubyFun/round0/varargs.rb
Normal file
17
RubyFun/round0/varargs.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
def shabang(*words)
|
||||
words.each do |word|
|
||||
puts word + ' shabanngggg'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def main()
|
||||
puts 'what ye have to say?'
|
||||
words = gets().chomp()
|
||||
shabang(*words.split())
|
||||
end
|
||||
|
||||
|
||||
if __FILE__ == $0
|
||||
main()
|
||||
end
|
Reference in New Issue
Block a user