Skip to content

Instantly share code, notes, and snippets.

@andyweiss1982
Created July 28, 2014 22:26
Show Gist options
  • Save andyweiss1982/b2b440fc1357941b9554 to your computer and use it in GitHub Desktop.
Save andyweiss1982/b2b440fc1357941b9554 to your computer and use it in GitHub Desktop.
Wyncode Modules and Methods
require "./wyncodemodules.rb"
WyncodeTests.float_fixer_test
WyncodeTests.bignum_digits_test
WyncodeTests.join_split_test
WyncodeTests.hash_genetics_test
WyncodeTests.class_methods_comparison_test
module WyncodeTests
def self.float_fixer_test
puts WyncodeMethods.float_fixer(1)
puts WyncodeMethods.float_fixer(1.0)
puts WyncodeMethods.float_fixer(nil)
puts WyncodeMethods.float_fixer({})
puts WyncodeMethods.float_fixer([])
puts WyncodeMethods.float_fixer(true)
puts WyncodeMethods.float_fixer("")
end
def self.bignum_digits_test
puts WyncodeMethods.bignum_digits(1)
puts WyncodeMethods.bignum_digits(1.0)
puts WyncodeMethods.bignum_digits(nil)
puts WyncodeMethods.bignum_digits({})
puts WyncodeMethods.bignum_digits([])
puts WyncodeMethods.bignum_digits(true)
puts WyncodeMethods.bignum_digits("")
end
def self.join_split_test
puts WyncodeMethods.join_split(1)
puts WyncodeMethods.join_split(1.0)
puts WyncodeMethods.join_split(nil)
puts WyncodeMethods.join_split({})
puts WyncodeMethods.join_split([1,2,3])
puts WyncodeMethods.join_split(true)
puts WyncodeMethods.join_split("")
end
def self.hash_genetics_test
puts WyncodeMethods.hash_genetics(1,2)
puts WyncodeMethods.hash_genetics(1.0,2.0)
puts WyncodeMethods.hash_genetics(nil, nil)
puts WyncodeMethods.hash_genetics({gender: :male}, {gender: :female})
puts WyncodeMethods.hash_genetics([],[])
puts WyncodeMethods.hash_genetics(true,false)
puts WyncodeMethods.hash_genetics("", "a")
end
def self.class_methods_comparison_test
puts WyncodeMethods.class_methods_comparison(1, 2.0)
puts WyncodeMethods.class_methods_comparison(2.0, nil)
puts WyncodeMethods.class_methods_comparison(nil, {})
puts WyncodeMethods.class_methods_comparison({}, [])
puts WyncodeMethods.class_methods_comparison([], true)
puts WyncodeMethods.class_methods_comparison(true, "")
end
end
module WyncodeMethods
def self.float_fixer (num = 0, *rest)
if num.is_a?(Float)
num = num.to_s.split(".")
d = (num[0]).to_i
c = num[1]
if c.to_i < 10
c = (c+"0").to_i
end
myhash = {dollars: d, cents: c}
elsif num.is_a?(Fixnum)
d = num
c = 0
myhash = {dollars: d, cents: c}
elsif rest.size > 0
puts "Seriously?"
else
d = 0
c = 0
myhash = {dollars: d, cents: c}
end
end
def self.bignum_digits (*rest)
if rest.size > 0
i = 1
until i.class == Bignum
i = i *10
i.class
end
digits = i.to_s.length
else
i = 1
until i.class == Bignum
i = i *10
i.class
end
digits = i.to_s.length
end
end
def self.join_split (myarray=[])
if myarray.is_a?(Array)
myarray = myarray.join.split(//).to_s
else
myarray = myarray
end
end
def self.hash_genetics (you={}, yourmate={})
if you.respond_to? :merge and yourmate.respond_to? :merge
child = yourmate.merge(you)
else
return nil
end
end
def self.class_methods_comparison (a, b)
(a.methods - b.methods).count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment