Skip to content

Instantly share code, notes, and snippets.

View saturnflyer's full-sized avatar
😀

Jim Gay saturnflyer

😀
View GitHub Profile
require 'resolv'
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if Resolv::DNS.new.getresources(value.split("@").last, Resolv::DNS::Resource::IN::MX).empty?
record.errors[attribute] << (options[:message] || "does not have a valid domain")
end
rescue Resolv::ResolvError, Resolv::ResolvTimeout
record.errors[attribute] << (options[:message] || "does not have a valid domain")
end
@saturnflyer
saturnflyer / prepended.rb
Last active May 11, 2017 12:54 — forked from cmar/prepended.rb
example of prepended class methods
class Foo
def self.say
p "hello from Foo"
end
end
module Bar
def say
super
p "hello from Bar"
@saturnflyer
saturnflyer / the_world_of_foos.rb
Last active July 16, 2019 16:49 — forked from zdennis/the_world_of_foos.rb
Given the below hierarchy how many ways can you think of to wrap the `Parent#foo` implementation so that `Grandchild1` and `Grandchild2` can have their own unique logic that executes after all of the mixin `foo`(s) but before the `Parent#foo` executes?
module N
def foo
puts "N: foo"
super
end
end
module O
def foo
puts "O: foo"