mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
Rubocop-inspired style tweaks
This commit is contained in:
@@ -7,24 +7,20 @@ class Class
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# module Comparable
|
||||
#===============================================================================
|
||||
unless Comparable.method_defined? :clamp
|
||||
module Comparable
|
||||
def clamp(min, max)
|
||||
if max-min<0
|
||||
if max - min < 0
|
||||
raise ArgumentError("min argument must be smaller than max argument")
|
||||
end
|
||||
return (self>max) ? max : (self<min) ? min : self
|
||||
return (self > max) ? max : (self < min) ? min : self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# class Boolean
|
||||
#===============================================================================
|
||||
@@ -34,32 +30,30 @@ class Boolean
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# class String
|
||||
#===============================================================================
|
||||
class String
|
||||
def starts_with?(str)
|
||||
proc = (self[0...str.length] == str) if self.length >= str.length
|
||||
return proc ? proc : false
|
||||
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 ? proc : false
|
||||
return proc || false
|
||||
end
|
||||
|
||||
def starts_with_vowel?
|
||||
return ['a','e','i','o','u'].include?(self[0,1].downcase)
|
||||
return ['a', 'e', 'i', 'o', 'u'].include?(self[0, 1].downcase)
|
||||
end
|
||||
|
||||
def first(n=1)
|
||||
def first(n = 1)
|
||||
return self[0...n]
|
||||
end
|
||||
|
||||
def last(n=1)
|
||||
def last(n = 1)
|
||||
return self[-n..-1] || self
|
||||
end
|
||||
|
||||
@@ -90,14 +84,14 @@ class String
|
||||
return blank
|
||||
end
|
||||
|
||||
def cut(bitmap,width)
|
||||
def cut(bitmap, width)
|
||||
string = self
|
||||
width -= bitmap.text_size("...").width
|
||||
string_width = 0
|
||||
text = []
|
||||
for char in string.scan(/./)
|
||||
wdh = bitmap.text_size(char).width
|
||||
next if (wdh+string_width) > width
|
||||
next if (wdh + string_width) > width
|
||||
string_width += wdh
|
||||
text.push(char)
|
||||
end
|
||||
@@ -110,8 +104,6 @@ class String
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# class Numeric
|
||||
#===============================================================================
|
||||
@@ -122,21 +114,17 @@ class Numeric
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# class Integer
|
||||
#===============================================================================
|
||||
class Integer
|
||||
# Returns an array containing each digit of the number in turn.
|
||||
def digits(base=10)
|
||||
def digits(base = 10)
|
||||
quotient, remainder = divmod(base)
|
||||
(quotient==0) ? [remainder] : quotient.digits(base).push(remainder)
|
||||
return (quotient == 0) ? [remainder] : quotient.digits(base).push(remainder)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# class Array
|
||||
#===============================================================================
|
||||
@@ -150,7 +138,7 @@ class Array
|
||||
end
|
||||
|
||||
def ^(other) # xor of two arrays
|
||||
return (self|other)-(self&other)
|
||||
return (self|other) - (self&other)
|
||||
end
|
||||
|
||||
def shuffle
|
||||
@@ -158,15 +146,14 @@ class Array
|
||||
end unless method_defined? :shuffle
|
||||
|
||||
def shuffle!
|
||||
(size-1).times do |i|
|
||||
r = i+rand(size-i)
|
||||
(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
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# module Enumerable
|
||||
#===============================================================================
|
||||
@@ -178,8 +165,6 @@ module Enumerable
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Kernel methods
|
||||
#===============================================================================
|
||||
|
||||
Reference in New Issue
Block a user