Last active
October 1, 2016 01:48
-
-
Save youcune/eebae7ce38685d4e237a12a1d40b4813 to your computer and use it in GitHub Desktop.
Rubyプログラミングキャンプ2016の課題
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
#!/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