Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Hex Color Reader (Ruby)
#ruby 2.3.1 def extract(mode, color) if !([:red, :green, :blue].include? mode) raise "ERROR: Wrong argument #{mode} to `extract'. Accepted modes are :red, :green, and :blue." end op2 = {red: 0xff0000, green: 0x00ff00, blue: 0x0000ff}[mode] shift = {red: 16, green: 8, blue: 0}[mode] return (color & op2) >> shift end puts extract(:blue, 0xff0c06)
run
|
edit
|
history
|
help
0
Arithmetic Operations, Function Calls, Recursion and more in Ruby
variables 1
testing ruby
ElaineBrown** rextester.com
Calculator
Testing out multiple variable returns in a method
ruby LRU cache with constant get/set
simple cache
Division Function without / or * signs
comments