Skip to content

Instantly share code, notes, and snippets.

@mvidner
Last active May 31, 2017 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvidner/2924e087d809efcc797c1cc6b791b0e2 to your computer and use it in GitHub Desktop.
Save mvidner/2924e087d809efcc797c1cc6b791b0e2 to your computer and use it in GitHub Desktop.
What do these files do when you run them with Ruby?
#!/usr/bin/ruby
# Ruby Gotcha Quiz, by Martin Vidner
# Aimed at people who have written something in Ruby already
def command(s)
system(s)
end
command "echo A"
command <<EOS
echo B
EOS
# The 1st program ends here. Will it work?
command = "echo C"
command "echo D"
# The 2nd program includes the 1st program and ends here. Will it work?
command <<EOS
echo E
EOS
# The 3rd program includes the above and ends here. Will it work?
command <<EOS
ls -l -a
EOS
# The 4th program includes the above and ends here. Will it work?
# If a program does not work, what kind of error occurs?
# - syntax error, the interpreter/compiler complains before running it
# - runtime error, it aborts while running
# - logic error, it runs without aborting but does something else than intended
# - style error, it works but your team will not accept it into the shared repo
#!/usr/bin/ruby
def command(s)
system(s)
end
command "echo A"
command <<EOS
echo B
EOS
#!/usr/bin/ruby
def command(s)
system(s)
end
command "echo A"
command <<EOS
echo B
EOS
command = "echo C"
command "echo D"
#!/usr/bin/ruby
def command(s)
system(s)
end
command "echo A"
command <<EOS
echo B
EOS
command = "echo C"
command "echo D"
command <<EOS
echo E
EOS
#!/usr/bin/ruby
def command(s)
system(s)
end
command "echo A"
command <<EOS
echo B
EOS
command = "echo C"
command "echo D"
command <<EOS
echo E
EOS
command <<EOS
ls -l -a
EOS
@mvidner
Copy link
Author

mvidner commented Jun 13, 2016

@bmwiedemann this is the problem that we hit when we catted the chef files in crowbar-openstack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment