Skip to content

Conversation

@blacktm
Copy link
Member

@blacktm blacktm commented Jun 24, 2021

These patterns are now all possible, each snipped would produce the same result:

#############################
# Pattern 1 — DSL

require 'ruby2d'

update do
  puts Time.now.to_f
end

show

#############################
# Pattern 2 — Singleton

require 'ruby2d'

Window.update do
  puts Time.now.to_f
end

Window.show

#############################
# Pattern 3 — Instance

require 'ruby2d'

game_window = Window.new

game_window.update do
  puts Time.now.to_f
end

game_window.show

#############################
# Pattern 4 — Class

require 'ruby2d'

class GameWindow < Ruby2D::Window
  def initialize
    super
  end

  def update
    puts Time.now.to_f
  end
end

GameWindow.new.show

@blacktm blacktm force-pushed the input-update-render branch from 0833dab to d410889 Compare June 28, 2021 19:20
@Nakilon
Copy link

Nakilon commented Jun 28, 2021

Why $ and not a constant? Is that variable is a subject of assinging it another objects?

@blacktm
Copy link
Member Author

blacktm commented Jun 28, 2021

@Nakilon Hey, that global is for the DSL to store its instance of the window, if the user chooses the DSL pattern. I could probably put that in the DSL module so we can call Ruby2D::DSL.window instead of $ruby2d_dsl_window if you think that's clearer.

@Nakilon
Copy link

Nakilon commented Jun 29, 2021

Probably Ruby2D could have an accessor like Ruby2D::dsl_window/Ruby2D::dsl_window=. I just mean $ variables are a huge global pile that would better be only used by Ruby stdlib while accessors in a constant (i.e. module Ruby2D) are at least hidden in its namespace.

@blacktm
Copy link
Member Author

blacktm commented Jun 29, 2021

@Nakilon Yea, for sure. I'll admit, I was having some accessor issues and got lazy. 😛 Figured it out, now Ruby2D::DSL.window will retrieve the window stored in the module's instance variable. Oh, and good idea to add the window= option too, in case the user wants to reassign it with their own window instance.

@blacktm blacktm marked this pull request as ready for review July 10, 2021 00:37
@blacktm blacktm merged commit e573609 into main Jul 10, 2021
@blacktm blacktm deleted the input-update-render branch July 10, 2021 00:39
blacktm added a commit that referenced this pull request Jul 20, 2021
DSL, singleton, instance, class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants