Skip to content

Instantly share code, notes, and snippets.

@youcune
Last active October 1, 2016 01:48
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 youcune/eebae7ce38685d4e237a12a1d40b4813 to your computer and use it in GitHub Desktop.
Save youcune/eebae7ce38685d4e237a12a1d40b4813 to your computer and use it in GitHub Desktop.
Rubyプログラミングキャンプ2016の課題
#!/usr/bin/env ruby
def to_hex(*args)
raise ArgumentError, '0-255の範囲のIntegerで指定してね' if args.any? { |_| !_.kind_of?(Integer) || !(0..255).include?(_) }
"##{args.map { |_| '%02x' % _ }.join}"
end
# test
p to_hex(0, 0, 0)
p to_hex(15, 16, 255)
p to_hex(255, 255, 255)
p to_hex(256, 256, 256)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment