Skip to content
Newer
Older
100644 72 lines (66 sloc) 1.29 KB
3ea3a08 @bovi Add documentation for Kernel
bovi authored May 2, 2012
1 ##
2 # Kernel
3 #
4 # ISO 15.3.1
e0d6430 add mruby sources
mimaki authored Apr 20, 2012
5 module Kernel
3ea3a08 @bovi Add documentation for Kernel
bovi authored May 2, 2012
6
7 ##
8 # Invoke method +print+ on STDOUT and passing +*args+
9 #
10 # ISO 15.3.1.2.10
e0d6430 add mruby sources
mimaki authored Apr 20, 2012
11 def print(*args)
12 i = 0
13 len = args.size
14 while i < len
15 __printstr__ args[i].to_s
16 i += 1
17 end
18 end
3ea3a08 @bovi Add documentation for Kernel
bovi authored May 2, 2012
19
20 ##
21 # Invoke method +puts+ on STDOUT and passing +*args*+
22 #
23 # ISO 15.3.1.2.11
e0d6430 add mruby sources
mimaki authored Apr 20, 2012
24 def puts(*args)
25 i = 0
26 len = args.size
27 while i < len
28 __printstr__ args[i].to_s
29 __printstr__ "\n"
30 i += 1
31 end
32 __printstr__ "\n" if len == 0
479df23 @matz puts should return nil; close #215
matz authored Jun 3, 2012
33 nil
e0d6430 add mruby sources
mimaki authored Apr 20, 2012
34 end
2728f30 @matz implement Kernel#p in Ruby
matz authored May 18, 2012
35
36 ##
37 # Print human readable object description
38 #
39 # ISO 15.3.1.3.34
40 def p(*args)
41 i = 0
42 len = args.size
43 while i < len
44 __printstr__ args[i].inspect
45 __printstr__ "\n"
46 i += 1
47 end
48 args[0]
49 end
e61bdbe @matz add printf method
matz authored Jun 20, 2012
50
e841135 @bovi raise NotImplementedError in case of sprintf is missing
bovi authored Jun 27, 2012
51 ##
52 # Invoke method +sprintf+ and pass +*args+ to it.
7f9b915 @bovi raise NoImplementedError also for sprintf in case it isn't available
bovi authored Jun 27, 2012
53 # Pass return value to +print+ of STDOUT.
e841135 @bovi raise NotImplementedError in case of sprintf is missing
bovi authored Jun 27, 2012
54 def printf(*args)
55 if Kernel.respond_to?(:sprintf)
2436ee8 @bovi Make printf optional based on sprintf
bovi authored Jun 21, 2012
56 __printstr__(sprintf(*args))
e841135 @bovi raise NotImplementedError in case of sprintf is missing
bovi authored Jun 27, 2012
57 else
58 raise NotImplementedError.new('sprintf not available')
2436ee8 @bovi Make printf optional based on sprintf
bovi authored Jun 21, 2012
59 end
e61bdbe @matz add printf method
matz authored Jun 20, 2012
60 end
7f9b915 @bovi raise NoImplementedError also for sprintf in case it isn't available
bovi authored Jun 27, 2012
61
62 ##
63 # +sprintf+ is defined in +src/sprintf.c+
64 # This stub method is only to inform the user
65 # that +sprintf+ isn't implemented.
66 unless Kernel.respond_to?(:sprintf)
67 def sprintf(*args)
68 raise NotImplementedError.new('sprintf not available')
69 end
70 end
e0d6430 add mruby sources
mimaki authored Apr 20, 2012
71 end
Something went wrong with that request. Please try again.