Skip to content

Instantly share code, notes, and snippets.

@ilyaruby
Created October 10, 2024 12:29
Show Gist options
  • Save ilyaruby/a1d8d17a75a3c14da88fe4b43ad8cd6b to your computer and use it in GitHub Desktop.
Save ilyaruby/a1d8d17a75a3c14da88fe4b43ad8cd6b to your computer and use it in GitHub Desktop.
class SVG
def self.rect(width, height, x, y)
"<rect width=\"#{width}\" height=\"#{height}\" x=\"#{x}\" y=\"#{y}\"/>"
end
def self.build(width, height, &block)
rect_output = instance_eval(&block)
"<svg width=\"#{width}\" height=\"#{height}\" xmlns=\"http://www.w3.org/2000/svg\">\n" +
" #{rect_output}\n" +
"</svg>"
end
end
output = SVG.build(300, 200) do
rect(200, 100, 10, 10)
end
puts output
# Выведет то, что и запрашивалось:
#
#<svg width="300" height="200" xmlns="http://www.w3.org/2000/svg">
# <rect width="200" height="100" x="10" y="10"/>
#</svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment