-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove compsci and NEWLINE dependency
- remove CompSci.numeric! and friends
- Loading branch information
Showing
7 changed files
with
6 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,10 @@ | ||
module CompSci | ||
NEWLINE = $/ # platform-default line separator | ||
|
||
# thanks apeiros | ||
# https://gist.github.com/rickhull/d0b579aa08c85430b0dc82a791ff12d6 | ||
def self.power_of?(num, base) | ||
return false if base <= 1 | ||
mod = 0 | ||
num, mod = num.divmod(base) until num == 1 || mod > 0 | ||
num, mod = num.divmod(base) until (num == 1) || (mod > 0) | ||
mod == 0 | ||
end | ||
|
||
def self.numeric!(num) | ||
raise(ArgumentError, num.inspect) unless num.is_a?(Numeric) | ||
num | ||
end | ||
|
||
def self.positive!(num) | ||
numeric!(num) | ||
raise(ArgumentError, num.inspect) unless num >= 0 | ||
num | ||
end | ||
|
||
def self.string!(str) | ||
raise(ArgumentError, str.inspect) unless str.is_a?(String) | ||
str | ||
end | ||
|
||
def self.nonempty!(str) | ||
string!(str) | ||
raise(ArgumentError, str.inspect) if str.empty? | ||
str | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
module CompSci | ||
NEWLINE: String | ||
|
||
def self.power_of?: (Numeric, Numeric) -> bool | ||
def self.numeric!: (untyped) -> Numeric | ||
def self.positive!: (untyped) -> Numeric | ||
def self.string!: (untyped) -> String | ||
def self.nonempty!: (untyped) -> String | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters