summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-07-17 23:56:57 +0900
committerYukihiro Matsumoto <[email protected]>2012-07-17 23:56:57 +0900
commita18699a80c14e0e44e904b7537d6d57463b6f39c (patch)
tree33ee1753cab2c9948c962cd7f06aca8a27f9456c
parent42cfe5c9f39bf5b32d4b4754c170cfeb947389b4 (diff)
downloadmruby-a18699a80c14e0e44e904b7537d6d57463b6f39c.tar.gz
mruby-a18699a80c14e0e44e904b7537d6d57463b6f39c.zip
print.rb: raise NotImplementedError for disabled methods
-rw-r--r--mrblib/print.rb117
1 files changed, 61 insertions, 56 deletions
diff --git a/mrblib/print.rb b/mrblib/print.rb
index c4ce74d6b..dea088e2b 100644
--- a/mrblib/print.rb
+++ b/mrblib/print.rb
@@ -3,71 +3,76 @@
#
# ISO 15.3.1
module Kernel
+ unless Kernel.respond_to?(:__printstr__)
+ def print(*a)
+ raise NotImplementedError.new('print not available')
+ end
+ def puts(*a)
+ raise NotImplementedError.new('puts not available')
+ end
+ def p(*a)
+ raise NotImplementedError.new('p not available')
+ end
+ def printf(*args)
+ raise NotImplementedError.new('printf not available')
+ end
+ else
+ unless Kernel.respond_to?(:sprintf)
+ def printf(*args)
+ raise NotImplementedError.new('printf not available')
+ end
+ def sprintf(*args)
+ raise NotImplementedError.new('sprintf not available')
+ end
+ end
- ##
- # Invoke method +print+ on STDOUT and passing +*args+
- #
- # ISO 15.3.1.2.10
- def print(*args)
- i = 0
- len = args.size
- while i < len
- __printstr__ args[i].to_s
- i += 1
+
+ ##
+ # Invoke method +print+ on STDOUT and passing +*args+
+ #
+ # ISO 15.3.1.2.10
+ def print(*args)
+ i = 0
+ len = args.size
+ while i < len
+ __printstr__ args[i].to_s
+ i += 1
+ end
end
- end
- ##
- # Invoke method +puts+ on STDOUT and passing +*args*+
- #
- # ISO 15.3.1.2.11
- def puts(*args)
- i = 0
- len = args.size
- while i < len
- __printstr__ args[i].to_s
- __printstr__ "\n"
- i += 1
+ ##
+ # Invoke method +puts+ on STDOUT and passing +*args*+
+ #
+ # ISO 15.3.1.2.11
+ def puts(*args)
+ i = 0
+ len = args.size
+ while i < len
+ __printstr__ args[i].to_s
+ __printstr__ "\n"
+ i += 1
+ end
+ __printstr__ "\n" if len == 0
+ nil
end
- __printstr__ "\n" if len == 0
- nil
- end
- ##
- # Print human readable object description
- #
- # ISO 15.3.1.3.34
- def p(*args)
- i = 0
- len = args.size
- while i < len
- __printstr__ args[i].inspect
- __printstr__ "\n"
- i += 1
+ ##
+ # Print human readable object description
+ #
+ # ISO 15.3.1.3.34
+ def p(*args)
+ i = 0
+ len = args.size
+ while i < len
+ __printstr__ args[i].inspect
+ __printstr__ "\n"
+ i += 1
+ end
+ args[0]
end
- args[0]
- end
- ##
- # Invoke method +sprintf+ and pass +*args+ to it.
- # Pass return value to +print+ of STDOUT.
- if Kernel.respond_to?(:sprintf) and Kernel.respond_to?(:__printstr__)
def printf(*args)
__printstr__(sprintf(*args))
end
- else
- def printf(*args)
- raise NotImplementedError.new('printf not available')
- end
- end
-
- ##
- # +sprintf+ is defined in +src/sprintf.c+
- # This stub method is only to inform the user
- # that +sprintf+ isn't implemented.
- unless Kernel.respond_to?(:sprintf)
- def sprintf(*args)
- raise NotImplementedError.new('sprintf not available')
- end
end
end