Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 79 lines (73 sloc) 1.551 kB
3ea3a08 @bovi Add documentation for Kernel
bovi authored
1 ##
2 # Kernel
3 #
4 # ISO 15.3.1
e0d6430 @mimaki add mruby sources
mimaki authored
5 module Kernel
a18699a @matz print.rb: raise NotImplementedError for disabled methods
matz authored
6 unless Kernel.respond_to?(:__printstr__)
7 def print(*a)
8 raise NotImplementedError.new('print not available')
9 end
10 def puts(*a)
11 raise NotImplementedError.new('puts not available')
12 end
13 def p(*a)
14 raise NotImplementedError.new('p not available')
15 end
16 def printf(*args)
17 raise NotImplementedError.new('printf not available')
18 end
19 else
20 unless Kernel.respond_to?(:sprintf)
21 def printf(*args)
22 raise NotImplementedError.new('printf not available')
23 end
24 def sprintf(*args)
25 raise NotImplementedError.new('sprintf not available')
26 end
27 end
3ea3a08 @bovi Add documentation for Kernel
bovi authored
28
a18699a @matz print.rb: raise NotImplementedError for disabled methods
matz authored
29
30 ##
31 # Invoke method +print+ on STDOUT and passing +*args+
32 #
33 # ISO 15.3.1.2.10
34 def print(*args)
35 i = 0
36 len = args.size
37 while i < len
38 __printstr__ args[i].to_s
39 i += 1
40 end
e0d6430 @mimaki add mruby sources
mimaki authored
41 end
3ea3a08 @bovi Add documentation for Kernel
bovi authored
42
a18699a @matz print.rb: raise NotImplementedError for disabled methods
matz authored
43 ##
44 # Invoke method +puts+ on STDOUT and passing +*args*+
45 #
46 # ISO 15.3.1.2.11
47 def puts(*args)
48 i = 0
49 len = args.size
50 while i < len
51 __printstr__ args[i].to_s
52 __printstr__ "\n"
53 i += 1
54 end
55 __printstr__ "\n" if len == 0
56 nil
e0d6430 @mimaki add mruby sources
mimaki authored
57 end
2728f30 @matz implement Kernel#p in Ruby
matz authored
58
a18699a @matz print.rb: raise NotImplementedError for disabled methods
matz authored
59 ##
60 # Print human readable object description
61 #
62 # ISO 15.3.1.3.34
63 def p(*args)
64 i = 0
65 len = args.size
66 while i < len
67 __printstr__ args[i].inspect
68 __printstr__ "\n"
69 i += 1
70 end
71 args[0]
2728f30 @matz implement Kernel#p in Ruby
matz authored
72 end
e61bdbe @matz add printf method
matz authored
73
a9247f7 @matz condition updated to preven printf from sprintf redefinition
matz authored
74 def printf(*args)
2436ee8 @bovi Make printf optional based on sprintf
bovi authored
75 __printstr__(sprintf(*args))
a9247f7 @matz condition updated to preven printf from sprintf redefinition
matz authored
76 end
7f9b915 @bovi raise NoImplementedError also for sprintf in case it isn't available
bovi authored
77 end
e0d6430 @mimaki add mruby sources
mimaki authored
78 end
Something went wrong with that request. Please try again.