This file contains hidden or 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
# simple camelize in ruby | |
class String | |
def camelize | |
split("_").map(&:capitalize).join | |
end | |
end | |
# "kamesh_test" => "KameshTest" |
This file contains hidden or 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
class ActiveRecord::Base | |
class << self | |
def random | |
all.at(rand(count)) | |
end | |
end | |
end | |
# User.random => #<User id: 10, ...> | |
# User.random => #<User id: 59, ...> |
This file contains hidden or 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 search(hash, keyword) | |
if (hash.respond_to?(:keys) && hash.keys.include?(keyword)) | |
hash[keyword] | |
elsif hash.respond_to?(:find) | |
result = nil | |
hash.values.find { |value| result = search(value, keyword) } | |
result | |
end | |
end |
NewerOlder