From 4e43a06f1b1c40999e6d709c9b36d4595d522788 Mon Sep 17 00:00:00 2001 From: Joni Savolainen Date: Fri, 26 Feb 2021 21:38:27 +0200 Subject: [PATCH] Remove unnecessary utilities (#99) - Comparable.clamp is already defined - Boolean class does not exist - String#start_with? already exists - String#end_with? already exists - String#bytesize already exists - String#capitalize already exists - Integer#digits already exists - Array#first and Array#last already exist - Array#shuffle already exists Ruby's own Integer#digits returns an array with the least significant digit as the first array element. That means that the method's only usage has to be appended with a call to Array#reverse. --- .../001_Technical/002_Ruby Utilities.rb | 83 ------------------- .../004_PokeBattle_SceneElements.rb | 3 +- 2 files changed, 2 insertions(+), 84 deletions(-) diff --git a/Data/Scripts/001_Technical/002_Ruby Utilities.rb b/Data/Scripts/001_Technical/002_Ruby Utilities.rb index 4e1733895..034fbe641 100644 --- a/Data/Scripts/001_Technical/002_Ruby Utilities.rb +++ b/Data/Scripts/001_Technical/002_Ruby Utilities.rb @@ -7,44 +7,10 @@ class Class end end -#=============================================================================== -# module Comparable -#=============================================================================== -unless Comparable.method_defined? :clamp - module Comparable - def clamp(min, max) - if max - min < 0 - raise ArgumentError("min argument must be smaller than max argument") - end - return (self > max) ? max : (self < min) ? min : self - end - end -end - -#=============================================================================== -# class Boolean -#=============================================================================== -class Boolean - def to_i - return self ? 1 : 0 - end -end - #=============================================================================== # class String #=============================================================================== class String - def starts_with?(str) - proc = (self[0...str.length] == str) if self.length >= str.length - return proc || false - end - - def ends_with?(str) - e = self.length - 1 - proc = (self[(e-str.length)...e] == str) if self.length >= str.length - return proc || false - end - def starts_with_vowel? return ['a', 'e', 'i', 'o', 'u'].include?(self[0, 1].downcase) end @@ -57,24 +23,6 @@ class String return self[-n..-1] || self end - def bytesize - return self.size - end - - def capitalize - proc = self.scan(/./) - proc[0] = proc[0].upcase - string = "" - for letter in proc - string += letter - end - return string - end - - def capitalize! - self.replace(self.capitalize) - end - def blank? blank = true s = self.scan(/./) @@ -114,44 +62,13 @@ class Numeric end end -#=============================================================================== -# class Integer -#=============================================================================== -class Integer - # Returns an array containing each digit of the number in turn. - def digits(base = 10) - quotient, remainder = divmod(base) - return (quotient == 0) ? [remainder] : quotient.digits(base).push(remainder) - end -end - #=============================================================================== # class Array #=============================================================================== class Array - def first - return self[0] - end - - def last - return self[self.length-1] - end - def ^(other) # xor of two arrays return (self|other) - (self&other) end - - def shuffle - dup.shuffle! - end unless method_defined? :shuffle - - def shuffle! - (size - 1).times do |i| - r = i + rand(size - i) - self[i], self[r] = self[r], self[i] - end - self - end unless method_defined? :shuffle! end #=============================================================================== diff --git a/Data/Scripts/012_Battle/005_Battle scene/004_PokeBattle_SceneElements.rb b/Data/Scripts/012_Battle/005_Battle scene/004_PokeBattle_SceneElements.rb index fcbdb4f56..456d71384 100644 --- a/Data/Scripts/012_Battle/005_Battle scene/004_PokeBattle_SceneElements.rb +++ b/Data/Scripts/012_Battle/005_Battle scene/004_PokeBattle_SceneElements.rb @@ -191,7 +191,8 @@ class PokemonDataBox < SpriteWrapper end def pbDrawNumber(number,btmp,startX,startY,align=0) - n = (number==-1) ? [10] : number.to_i.digits # -1 means draw the / character + # -1 means draw the / character + n = (number == -1) ? [10] : number.to_i.digits.reverse charWidth = @numbersBitmap.width/11 charHeight = @numbersBitmap.height startX -= charWidth*n.length if align==1