Class: Ruboty::Handlers::RubyPersistence
- Inherits:
-
Base
- Object
- Base
- Ruboty::Handlers::RubyPersistence
- Defined in:
- lib/ruboty/handlers/ruby_persistence.rb
Constant Summary collapse
- NAMESPACE =
'ruby_persistence'.freeze
Instance Method Summary collapse
- #define(message) ⇒ Object
-
#initialize ⇒ RubyPersistence
constructor
A new instance of RubyPersistence.
- #list(message) ⇒ Object
- #undefine(message) ⇒ Object
Constructor Details
#initialize ⇒ RubyPersistence
Returns a new instance of RubyPersistence.
26 27 28 29 |
# File 'lib/ruboty/handlers/ruby_persistence.rb', line 26 def initialize(*) super restore end |
Instance Method Details
#define(message) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/ruboty/handlers/ruby_persistence.rb', line 31 def define() name = [:name] if !variables.key?(name) && (method = predefined_method(name)) .reply("Error: `#{name}` is predefined by `#{method.owner}`") else define_and_persist_variable() end end |
#list(message) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/ruboty/handlers/ruby_persistence.rb', line 53 def list() summary = variables.map do |name, value| "#{name}: #{value.inspect}" end.join("\n") .reply(summary, code: true) end |
#undefine(message) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ruboty/handlers/ruby_persistence.rb', line 41 def undefine() name = [:name] if variables[name] undefine_variable(name) variables.delete(name) .reply("`#{name}` is now undefined") else .reply("Error: No such variable `#{name}`") end end |