diff options
| author | Chris Aporta <[email protected]> | 2016-03-13 13:49:19 -0400 |
|---|---|---|
| committer | Chris Aporta <[email protected]> | 2016-03-13 13:49:19 -0400 |
| commit | cc85864f0936262f7bab586f9f2b22cd08059a12 (patch) | |
| tree | 1518e096d57e60cfe2c4bc968c0879292e49c98b /lib | |
| parent | 96823748c68c65d1d54df7b0d9336df080b62d58 (diff) | |
| download | ruby2d-cc85864f0936262f7bab586f9f2b22cd08059a12.tar.gz ruby2d-cc85864f0936262f7bab586f9f2b22cd08059a12.zip | |
refactor set method to return true or false
in previous implementation, set method was returning either the value of @height or nil (as evaluated by final if statement).
returning boolean to reflect either successful or unsuccessful assignment seems to match return patterns in other window methods (e.g. #add, #remove).
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ruby2d/window.rb | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb index 322d94c..f5f81a1 100644 --- a/lib/ruby2d/window.rb +++ b/lib/ruby2d/window.rb @@ -1,4 +1,5 @@ # window.rb +require 'pry' module Ruby2D class Window @@ -38,16 +39,15 @@ module Ruby2D end def set(opts) - if opts.include? :title - @title = opts[:title] - end - - if opts.include? :width - @width = opts[:width] - end - - if opts.include? :height - @height = opts[:height] + valid_keys = [:title, :width, :height] + valid_opts = opts.reject { |k| !valid_keys.include?(k) } + if !valid_opts.empty? + @title = valid_opts[:title] + @width = valid_opts[:width] + @height = valid_opts[:height] + return true + else + return false end end |
