Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Test-integerness/Ruby/test-integerness.rb
Normal file
13
Task/Test-integerness/Ruby/test-integerness.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class Numeric
|
||||
def to_i?
|
||||
self == self.to_i rescue false
|
||||
end
|
||||
end
|
||||
|
||||
# Demo
|
||||
ar = [25.000000, 24.999999, 25.000100, -2.1e120, -5e-2, # Floats
|
||||
Float::NAN, Float::INFINITY, # more Floats
|
||||
2r, 2.5r, # Rationals
|
||||
2+0i, 2+0.0i, 5-5i] # Complexes
|
||||
|
||||
ar.each{|num| puts "#{num} integer? #{num.to_i?}" }
|
||||
Loading…
Add table
Add a link
Reference in a new issue