Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save surrealdetective/5850056 to your computer and use it in GitHub Desktop.
Save surrealdetective/5850056 to your computer and use it in GitHub Desktop.
warmup enumerable
module Enumerable
def flatiron_flatten(hashy = @hash)
hashy.delete_if {|key, value| value == nil}
hashy.each do |pair|
if pair[1].class == Hash
flatiron_flatten(pair[1])
end
end
end
end
class Student
include Enumerable
attr_accessor :hash
def initialize
@hash = {:a=>"a", :b=>"b", :c=>"c", :d=>nil, :e=> {:f => 'f', :g => nil}}
end
end
alex = Student.new
puts alex.hash
alex.flatiron_flatten
puts alex.hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment