ruby.rb 531 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/ruby
  2. # Program to find the factorial of a number
  3. def fact(n)
  4. if n == 0
  5. 1
  6. else
  7. n * fact(n-1)
  8. end
  9. end
  10. puts fact(ARGV[0].to_i)
  11. class Range
  12. def to_json(*a)
  13. {
  14. 'json_class' => self.class.name, # = 'Range'
  15. 'data' => [ first, last, exclude_end? ]
  16. }.to_json(*a)
  17. end
  18. end
  19. {:id => ?", :key => "value"}
  20. herDocs = [<<'FOO', <<BAR, <<-BAZ, <<-`EXEC`] #comment
  21. FOO #{literal}
  22. FOO
  23. BAR #{fact(10)}
  24. BAR
  25. BAZ indented
  26. BAZ
  27. echo hi
  28. EXEC
  29. puts herDocs