mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Improve.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									354af9da36
								
							
						
					
					
						commit
						63406c4971
					
				
					 2 changed files with 9 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -1,13 +1,13 @@
 | 
			
		|||
line = ''
 | 
			
		||||
indent=0
 | 
			
		||||
indent = 0
 | 
			
		||||
$stdout.sync = TRUE
 | 
			
		||||
print "ruby> "
 | 
			
		||||
while TRUE
 | 
			
		||||
loop do
 | 
			
		||||
  l = gets
 | 
			
		||||
  unless l
 | 
			
		||||
    break if line == ''
 | 
			
		||||
  if l.nil?
 | 
			
		||||
    break if line.empty?
 | 
			
		||||
  else
 | 
			
		||||
    line = line + l 
 | 
			
		||||
    line += l
 | 
			
		||||
    if l =~ /,\s*$/
 | 
			
		||||
      print "ruby| "
 | 
			
		||||
      next
 | 
			
		||||
| 
						 | 
				
			
			@ -32,10 +32,9 @@ while TRUE
 | 
			
		|||
  begin
 | 
			
		||||
    print eval(line).inspect, "\n"
 | 
			
		||||
  rescue ScriptError, StandardError
 | 
			
		||||
    $! = 'exception raised' unless $!
 | 
			
		||||
    print "ERR: ", $!, "\n"
 | 
			
		||||
    printf "ERR: %s\n", $! || 'exception raised'
 | 
			
		||||
  end
 | 
			
		||||
  break if not l
 | 
			
		||||
  break if l.nil?
 | 
			
		||||
  line = ''
 | 
			
		||||
  print "ruby> "
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,8 @@
 | 
			
		|||
def fact(n)
 | 
			
		||||
  return 1 if n == 0
 | 
			
		||||
  f = 1
 | 
			
		||||
  while n>0
 | 
			
		||||
    f *= n
 | 
			
		||||
    n -= 1
 | 
			
		||||
  n.downto(1) do |i|
 | 
			
		||||
    f *= i
 | 
			
		||||
  end
 | 
			
		||||
  return f
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue