Last active
August 29, 2015 14:01
-
-
Save davydovanton/f4b87fdcf16bad7346fe to your computer and use it in GitHub Desktop.
Ruby tips
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
# Check type class in STI in rails | |
Post.uniq.pluck(:type).each do |class_type| | |
method_name = class_type.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase + '?' | |
define_method method_name do | |
type == class_type | |
end | |
end | |
# Use mb_chars.uppcase for many varibles | |
first_name, middle_name, last_name = [:first_name, :middle_name, :last_name].map{ |i| user.send(i).mb_chars.capitalize } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment