Skip to content

Instantly share code, notes, and snippets.

# Create a file my_modeule.rb
# Include it in your application load path (Standard: app/lib )
# FILE CONTENTS BEGIN HERE
module MyModule
def self.included(base)
base.extend ClassMethods
class << base
attr_accessor :class_variable
end
module FooModule
def say_hello
"Hello!"
end
end
class FooClass
include FooModule
end
10.3 - 10
# 0.300000000000001
a = 10.3 - 10
# 0.300000000000001
b = 0.300000000000000
# 0.300000000000000
a == b
# false
(a + 10) == (b + 10)
# true
def self.auto_link_content(content)
# Splits all HTML tags, except <a></a> tags. Keeps <a></a> tags as whole
# so that we don't accidentally link already linked Keywords
word_groups = content.split(/(<a[^>]*>.+?<\/a>|<\/?[^>]*>|[.]|,|['"]+)/i)
word_groups.collect! do |words|
(!words.match(/<\/?[^>]*>|[.]+|,+/) && words.match(/([a-zA-Z]+)/)) ? link_it(words) : words
end
word_groups.join
end