Created
August 30, 2024 20:23
-
-
Save AndyObtiva/b6e1a5cef66361fc4d475eb3df5f454e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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