Class: KhoinguyenEhTodoList::Memento
- Inherits:
-
Object
- Object
- KhoinguyenEhTodoList::Memento
- Defined in:
- lib/khoinguyen_eh_todo_list/memento.rb
Overview
Represents a memento for the undo and redo history
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
-
.from_yaml(yaml) ⇒ Memento
Deserializes memento from YAML.
Instance Method Summary collapse
-
#initialize(action, data) ⇒ Memento
constructor
A new instance of Memento.
-
#to_yaml ⇒ String
Serializes the memento to YAML.
Constructor Details
#initialize(action, data) ⇒ Memento
Returns a new instance of Memento.
12 13 14 15 |
# File 'lib/khoinguyen_eh_todo_list/memento.rb', line 12 def initialize(action, data) @action = action @data = data end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
8 9 10 |
# File 'lib/khoinguyen_eh_todo_list/memento.rb', line 8 def action @action end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/khoinguyen_eh_todo_list/memento.rb', line 8 def data @data end |
Class Method Details
.from_yaml(yaml) ⇒ Memento
Deserializes memento from YAML
26 27 28 29 |
# File 'lib/khoinguyen_eh_todo_list/memento.rb', line 26 def self.from_yaml(yaml) state = YAML.safe_load(yaml) new(state[:action], state[:data]) end |
Instance Method Details
#to_yaml ⇒ String
Serializes the memento to YAML
19 20 21 |
# File 'lib/khoinguyen_eh_todo_list/memento.rb', line 19 def to_yaml YAML.dump({ action: @action, data: @data }) end |