Created
October 10, 2024 12:29
-
-
Save ilyaruby/a1d8d17a75a3c14da88fe4b43ad8cd6b to your computer and use it in GitHub Desktop.
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 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