Method: Sass::Script::Functions#rgb

Defined in:
lib/sass/script/functions.rb

#rgb($red, $green, $blue) ⇒ Sass::Script::Value::Color

Creates a Color object from red, green, and blue values.

Parameters:

  • $red (Sass::Script::Value::Number)

    The amount of red in the color. Must be between 0 and 255 inclusive, or between 0% and 100% inclusive

  • $green (Sass::Script::Value::Number)

    The amount of green in the color. Must be between 0 and 255 inclusive, or between 0% and 100% inclusive

  • $blue (Sass::Script::Value::Number)

    The amount of blue in the color. Must be between 0 and 255 inclusive, or between 0% and 100% inclusive

Returns:

Raises:

  • (ArgumentError)

    if any parameter is the wrong type or out of bounds

See Also:



651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'lib/sass/script/functions.rb', line 651

def rgb(red, green = nil, blue = nil)
  if green.nil?
    return unquoted_string("rgb(#{red})") if var?(red)
    raise ArgumentError.new("wrong number of arguments (1 for 3)")
  elsif blue.nil?
    return unquoted_string("rgb(#{red}, #{green})") if var?(red) || var?(green)
    raise ArgumentError.new("wrong number of arguments (2 for 3)")
  end

  if special_number?(red) || special_number?(green) || special_number?(blue)
    return unquoted_string("rgb(#{red}, #{green}, #{blue})")
  end
  assert_type red, :Number, :red
  assert_type green, :Number, :green
  assert_type blue, :Number, :blue

  color_attrs = [
    percentage_or_unitless(red, 255, "red"),
    percentage_or_unitless(green, 255, "green"),
    percentage_or_unitless(blue, 255, "blue")
  ]

  # Don't store the string representation for function-created colors, both
  # because it's not very useful and because some functions aren't supported
  # on older browsers.
  Sass::Script::Value::Color.new(color_attrs)
end