Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AndyObtiva/b6e1a5cef66361fc4d475eb3df5f454e to your computer and use it in GitHub Desktop.
Save AndyObtiva/b6e1a5cef66361fc4d475eb3df5f454e to your computer and use it in GitHub Desktop.
# Source: https://github.com/AndyObtiva/glimmer-dsl-web/blob/master/lib/glimmer-dsl-web/samples/regular/todo_mvc/models/todo.rb
Todo = Struct.new(:task, :completed, :editing, :deleted, keyword_init: true) do
alias completed? completed
alias editing? editing
alias deleted? deleted
def active = !completed
alias active? active
def start_editing
return if editing?
@original_task = task
self.editing = true
end
def cancel_editing
return unless editing?
self.task = @original_task
self.editing = false
end
def save_editing
return unless editing?
self.editing = false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment