Class: Spade::Shell
- Inherits:
-
Object
- Object
- Spade::Shell
- Defined in:
- lib/spade/shell.rb
Constant Summary collapse
- METHODS =
[:to_s, :exit, :quit, :help, :evalrb, :inspectjs]
Instance Method Summary collapse
- #evalrb(str) ⇒ Object
- #exit(status = 0) ⇒ Object (also: #quit)
- #help(*args) ⇒ Object
-
#initialize ⇒ Shell
constructor
A new instance of Shell.
- #inject(ctx) ⇒ Object
- #inspectjs(obj) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Shell
Returns a new instance of Shell.
16 17 18 19 |
# File 'lib/spade/shell.rb', line 16 def initialize @history_path = File.("~/.spadehistory") load_history end |
Instance Method Details
#evalrb(str) ⇒ Object
53 54 55 |
# File 'lib/spade/shell.rb', line 53 def evalrb(str) Kernel.eval str, binding end |
#exit(status = 0) ⇒ Object Also known as: quit
31 32 33 34 35 |
# File 'lib/spade/shell.rb', line 31 def exit(status=0) save_history ensure @ctx.reactor.exit(status) end |
#help(*args) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/spade/shell.rb', line 39 def help(*args) <<-HELP print(msg) print msg to STDOUT exit(status = 0) exit the shell also: quit() evalrb(source) evaluate some ruby source HELP end |
#inject(ctx) ⇒ Object
21 22 23 24 25 |
# File 'lib/spade/shell.rb', line 21 def inject(ctx) @ctx = ctx METHODS.each{|meth| @ctx[meth.to_s] = method(meth) } true end |
#inspectjs(obj) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/spade/shell.rb', line 57 def inspectjs(obj) # check for exact class match so we don't match things like arrays spacer = (obj.class == V8::Object) ? 2 : nil # the self[] uses the JS version of JSON json = @ctx['JSON'].stringify(obj, nil, spacer) # Some things can't be converted into json json || obj.inspect end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/spade/shell.rb', line 27 def to_s "[object Shell]" end |