Created
July 25, 2014 16:52
-
-
Save andyweiss1982/183c4546f34f8010afc1 to your computer and use it in GitHub Desktop.
Wyncode methods
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
def 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 float_fixer_test | |
puts float_fixer(1) | |
puts float_fixer(1.0) | |
puts float_fixer(nil) | |
puts float_fixer({}) | |
puts float_fixer([]) | |
puts float_fixer(true) | |
puts float_fixer("") | |
end | |
float_fixer_test | |
def 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 bignum_digits_test | |
puts bignum_digits(1) | |
puts bignum_digits(1.0) | |
puts bignum_digits(nil) | |
puts bignum_digits({}) | |
puts bignum_digits([]) | |
puts bignum_digits(true) | |
puts bignum_digits("") | |
end | |
bignum_digits_test | |
def join_split (myarray=[]) | |
if myarray.is_a?(Array) | |
myarray = myarray.join.split(//).to_s | |
else | |
myarray = myarray | |
end | |
end | |
def join_split_test | |
puts join_split(1) | |
puts join_split(1.0) | |
puts join_split(nil) | |
puts join_split({}) | |
puts join_split([1,2,3]) | |
puts join_split(true) | |
puts join_split("") | |
end | |
join_split_test | |
def hash_genetics (you={}, yourmate={}) | |
if you.respond_to? :merge and yourmate.respond_to? :merge | |
child = yourmate.merge(you) | |
else | |
return nil | |
end | |
end | |
def hash_genetics_test | |
puts hash_genetics(1,2) | |
puts hash_genetics(1.0,2.0) | |
puts hash_genetics(nil, nil) | |
puts hash_genetics({gender: :male}, {gender: :female}) | |
puts hash_genetics([],[]) | |
puts hash_genetics(true,false) | |
puts hash_genetics("", "a") | |
end | |
hash_genetics_test | |
def class_methods_comparison (a, b) | |
(a.methods - b.methods).count | |
end | |
def class_methods_comparison_test | |
puts class_methods_comparison(1, 2.0) | |
puts class_methods_comparison(2.0, nil) | |
puts class_methods_comparison(nil, {}) | |
puts class_methods_comparison({}, []) | |
puts class_methods_comparison([], true) | |
puts class_methods_comparison(true, "") | |
end | |
class_methods_comparison_test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment