Ruby table script


SUBMITTED BY: Guest

DATE: May 21, 2015, 1:51 p.m.

FORMAT: Ruby

SIZE: 1.6 kB

HITS: 726

  1. if ARGV.length <hr><b>table1.rb</b>
  2. <pre class="brush: ruby">#!/usr/bin/env ruby
  3. if ARGV.length < 1
  4. puts "usage: #{$0} number."
  5. exit -1
  6. end
  7. num = ARGV[0].to_i
  8. 1.upto(10) do |count|
  9. # puts "#{num} x #{count} = #{num * count}"
  10. puts "%3d x %2d = %4d" % [num, count, num*count]
  11. end
  12. (1..10).each do |count|
  13. puts "%3d x %2d = %4d" % [num, count, num*count]
  14. end
  15. </pre><hr><b>taint-test.rb</b>
  16. <pre class="brush: ruby">
  17. a = "Test string..."
  18. a.taint
  19. puts a
  20. a << "new value" unless a.tainted?
  21. puts a
  22. </pre><hr><b>test-equal.rb</b>
  23. <pre class="brush: ruby">a = "John"
  24. b = "John"
  25. c = a
  26. puts "a -> b: Same..." if a.equal? b
  27. puts "c -> a: Same..." if c.equal? a
  28. puts "c -> b: Same..." if c.equal? b
  29. </pre><hr><b>to_methods.rb</b>
  30. <pre class="brush: ruby">#!/usr/bin/env ruby
  31. # Print all methods starting with to_* from a class.
  32. puts File.methods.select {|m| m.start_with? "to_" }.join "\n"
  33. </pre><hr><b>yield-test.rb</b>
  34. <pre class="brush: ruby">#!/usr/bin/env ruby
  35. def foo
  36. yield
  37. yield
  38. end
  39. foo do
  40. puts "Hello"
  41. end
  42. </pre><hr><b>yield2.rb</b>
  43. <pre class="brush: ruby">#!/usr/bin/env ruby
  44. def count10
  45. yield "Hello"
  46. yield 10
  47. yield "Test String"
  48. yield "Hi"
  49. end
  50. count10 do |x|
  51. puts x
  52. end
  53. </pre><hr>
  54. - See more at: http://www.chandrashekar.info/vault/ruby-scripts/simple.html#sthash.E4LdXgyV.dpuf

comments powered by Disqus