From cc85864f0936262f7bab586f9f2b22cd08059a12 Mon Sep 17 00:00:00 2001 From: Chris Aporta Date: Sun, 13 Mar 2016 13:49:19 -0400 Subject: 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). --- lib/ruby2d/window.rb | 20 ++++++++++---------- tests/testcard.rb | 1 + 2 files changed, 11 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 diff --git a/tests/testcard.rb b/tests/testcard.rb index 1ab2267..4954d20 100644 --- a/tests/testcard.rb +++ b/tests/testcard.rb @@ -1,5 +1,6 @@ require 'ruby2d' +binding.pry set width: 700, height: 500, title: "Ruby 2D – Testcard" # Read window attributes -- cgit v1.2.3 From b62de933e0957991d99b8af2e040b8252dc8587d Mon Sep 17 00:00:00 2001 From: Chris Aporta Date: Sun, 13 Mar 2016 13:50:30 -0400 Subject: remove binding whoops --- tests/testcard.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testcard.rb b/tests/testcard.rb index 4954d20..1ab2267 100644 --- a/tests/testcard.rb +++ b/tests/testcard.rb @@ -1,6 +1,5 @@ require 'ruby2d' -binding.pry set width: 700, height: 500, title: "Ruby 2D – Testcard" # Read window attributes -- cgit v1.2.3 From 721b7dc6d75dd3cd3ddd1a5c1a4a2ac2dea44f14 Mon Sep 17 00:00:00 2001 From: Chris Aporta Date: Sun, 13 Mar 2016 14:12:30 -0400 Subject: remove require statement for pry in window.rb --- lib/ruby2d/window.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb index f5f81a1..1b3698e 100644 --- a/lib/ruby2d/window.rb +++ b/lib/ruby2d/window.rb @@ -1,5 +1,4 @@ # window.rb -require 'pry' module Ruby2D class Window -- cgit v1.2.3