mirror of
https://github.com/PeterCamilleri/fOOrth
synced 2024-11-16 07:47:56 +01:00
SIRE enhancements.
This commit is contained in:
parent
5877817486
commit
3bda4bb203
3 changed files with 42 additions and 31 deletions
|
@ -13,10 +13,9 @@ module XfOOrth
|
||||||
#<br>Parameters:
|
#<br>Parameters:
|
||||||
#* target_class - The Ruby class to be wrapped.
|
#* target_class - The Ruby class to be wrapped.
|
||||||
#* foorth_parent - The fOOrth class that serves as parent.
|
#* foorth_parent - The fOOrth class that serves as parent.
|
||||||
#* exclusives - Are exclusive methods to be allowed?
|
|
||||||
#<br>Returns:
|
#<br>Returns:
|
||||||
#* The newly created proxy class.
|
#* 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_parent) {foorth_parent}
|
||||||
target_class.define_singleton_method(:foorth_class) {XfOOrth.class_class}
|
target_class.define_singleton_method(:foorth_class) {XfOOrth.class_class}
|
||||||
target_class.define_singleton_method(:shared) {@shared ||= {}}
|
target_class.define_singleton_method(:shared) {@shared ||= {}}
|
||||||
|
@ -25,7 +24,7 @@ module XfOOrth
|
||||||
&lambda {target_class})
|
&lambda {target_class})
|
||||||
|
|
||||||
target_class.send(:define_method, :name,
|
target_class.send(:define_method, :name,
|
||||||
&lambda {"#{foorth_class.name} instance <#{@name}>."})
|
&lambda {"#{foorth_class.name} instance."})
|
||||||
|
|
||||||
target_class.extend(SharedCache)
|
target_class.extend(SharedCache)
|
||||||
target_class.extend(Shared)
|
target_class.extend(Shared)
|
||||||
|
|
65
sire.rb
65
sire.rb
|
@ -45,7 +45,7 @@ end
|
||||||
class SIRE
|
class SIRE
|
||||||
#Set up the interactive session.
|
#Set up the interactive session.
|
||||||
def initialize
|
def initialize
|
||||||
@done = false
|
@_done = false
|
||||||
@running = false
|
@running = false
|
||||||
|
|
||||||
puts "Welcome to a Simple Interactive Ruby Environment\n"
|
puts "Welcome to a Simple Interactive Ruby Environment\n"
|
||||||
|
@ -54,39 +54,48 @@ class SIRE
|
||||||
|
|
||||||
#Quit the interactive session.
|
#Quit the interactive session.
|
||||||
def q
|
def q
|
||||||
@done = true
|
@_done = true
|
||||||
puts
|
puts
|
||||||
"Bye bye for now!"
|
"Bye bye for now!"
|
||||||
end
|
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.
|
#Run the interactive session.
|
||||||
def run_sire
|
def run_sire
|
||||||
until @done
|
until @_done
|
||||||
begin
|
@_break = false
|
||||||
line = Readline.readline('SIRE>', true)
|
exec_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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "\n\n"
|
puts "\n\n"
|
||||||
|
|
3
t.txt
Normal file
3
t.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
XfOOrth.create_proxy(Numeric, XfOOrth.object_class)
|
||||||
|
Numeric.name
|
||||||
|
(4).name
|
Loading…
Reference in a new issue