Skip to content

Instantly share code, notes, and snippets.

@davydovanton
Last active August 29, 2015 14:01
Show Gist options
  • Save davydovanton/f4b87fdcf16bad7346fe to your computer and use it in GitHub Desktop.
Save davydovanton/f4b87fdcf16bad7346fe to your computer and use it in GitHub Desktop.
Ruby tips
# 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