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
x - x = 1 | |
∴ 0 = 1 (!?) |
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
x = 1 | |
y = x + 1 |
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
y = x + 1 | |
∴ x = y - 1 |
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 module_split(module_path, separator = "::") | |
modules = module_path.split(separator) | |
modules.length.downto(1).map { |n| modules.first(n).join(separator) } | |
end | |
module_split("W::X::Y::Z") |
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 CssBlock | |
# We'll add some methods in here. | |
end |
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 CssBlock | |
attr_reader :selector, :properties | |
def initialize(selector, properties = {}) | |
@selector = selector.dup.freeze | |
@properties = properties.dup.freeze | |
end | |
end |
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 CssBlock | |
# ... | |
def set(key, value = nil) | |
new_properties = if key.is_a?(Hash) | |
key | |
elsif !value.nil? | |
{ | |
key => value |
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 CssBlock | |
# ... | |
def to_s | |
serialised_properties = self.properties.inject([]) do |acc, (k, v)| | |
acc + ["#{k}: #{v}"] | |
end | |
"#{self.selector} { #{serialised_properties.join("; ") } }" |
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
CssBlock.new("#some_id .class a").set("color", "#FFF").set({ "color" => "#000", "text-decoration" => "underline"}) # => "#some_id .class a { color: #000; text-decoration: underline }" |
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 CssBlock | |
attr_reader :selector, :properties | |
def initialize(selector, properties = {}) | |
@selector = selector.dup.freeze | |
@properties = properties.dup.freeze | |
end | |
def set(key, value = nil) | |
new_properties = if key.is_a?(Hash) |