SIRE enhancements.

This commit is contained in:
Peter Camilleri 2014-10-15 12:27:05 -04:00
parent 5877817486
commit 3bda4bb203
3 changed files with 42 additions and 31 deletions

View file

@ -13,10 +13,9 @@ module XfOOrth
#<br>Parameters:
#* target_class - The Ruby class to be wrapped.
#* foorth_parent - The fOOrth class that serves as parent.
#* exclusives - Are exclusive methods to be allowed?
#<br>Returns:
#* The newly created proxy class.
def self.create_proxy(target_class, foorth_parent, exclusives=false)
def self.create_proxy(target_class, foorth_parent)
target_class.define_singleton_method(:foorth_parent) {foorth_parent}
target_class.define_singleton_method(:foorth_class) {XfOOrth.class_class}
target_class.define_singleton_method(:shared) {@shared ||= {}}
@ -25,7 +24,7 @@ module XfOOrth
&lambda {target_class})
target_class.send(:define_method, :name,
&lambda {"#{foorth_class.name} instance <#{@name}>."})
&lambda {"#{foorth_class.name} instance."})
target_class.extend(SharedCache)
target_class.extend(Shared)

65
sire.rb
View file

@ -45,7 +45,7 @@ end
class SIRE
#Set up the interactive session.
def initialize
@done = false
@_done = false
@running = false
puts "Welcome to a Simple Interactive Ruby Environment\n"
@ -54,39 +54,48 @@ class SIRE
#Quit the interactive session.
def q
@done = true
@_done = true
puts
"Bye bye for now!"
end
#Load and run a file
def l(file_name)
@_break = false
lines = IO.readlines(file_name)
lines.each do |line|
exec_line(line)
return if @_break
end
"End of file '#{file_name}'."
end
#Execute a single line.
def exec_line(line)
result = eval line
pp result unless line.length == 0
rescue Interrupt => e
@_break = true
puts "\nExecution Interrupted!"
puts "\n#{e.class} detected: #{e}\n"
puts e.backtrace
puts "\n"
rescue Exception => e
@_break = true
puts "\n#{e.class} detected: #{e}\n"
puts e.backtrace
puts
end
#Run the interactive session.
def run_sire
until @done
begin
line = Readline.readline('SIRE>', true)
@running = true
result = eval line
@running = false
pp result unless line.length == 0
rescue Interrupt => e
if @running
@running = false
puts "\nExecution Interrupted!"
puts "\n#{e.class} detected: #{e}\n"
puts e.backtrace
else
puts "\nI'm outta here!'"
@done = true
end
puts "\n"
rescue Exception => e
puts "\n#{e.class} detected: #{e}\n"
puts e.backtrace
puts
end
until @_done
@_break = false
exec_line(Readline.readline('SIRE>', true))
end
puts "\n\n"

3
t.txt Normal file
View file

@ -0,0 +1,3 @@
XfOOrth.create_proxy(Numeric, XfOOrth.object_class)
Numeric.name
(4).name