Skip to content

Commit

Permalink
print.rb: raise NotImplementedError for disabled methods
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Jul 17, 2012
1 parent 42cfe5c commit a18699a
Showing 1 changed file with 61 additions and 56 deletions.
117 changes: 61 additions & 56 deletions mrblib/print.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a18699a

Please sign in to comment.