You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
531 B
Ruby
35 lines
531 B
Ruby
10 years ago
|
#!/usr/bin/ruby
|
||
|
|
||
|
# Program to find the factorial of a number
|
||
|
def fact(n)
|
||
|
if n == 0
|
||
|
1
|
||
|
else
|
||
|
n * fact(n-1)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
puts fact(ARGV[0].to_i)
|
||
|
|
||
|
class Range
|
||
|
def to_json(*a)
|
||
|
{
|
||
|
'json_class' => self.class.name, # = 'Range'
|
||
|
'data' => [ first, last, exclude_end? ]
|
||
|
}.to_json(*a)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
{:id => 34, :key => "value"}
|
||
|
|
||
|
|
||
|
herDocs = [<<'FOO', <<BAR, <<-BAZ, <<-`EXEC`] #comment
|
||
|
FOO #{literal}
|
||
|
FOO
|
||
|
BAR #{fact(10)}
|
||
|
BAR
|
||
|
BAZ indented
|
||
|
BAZ
|
||
|
echo hi
|
||
|
EXEC
|
||
|
puts herDocs
|