Open In App

Ruby | Vector component() function

Last Updated : 07 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
The component() is an inbuilt method in Ruby returns element at index i in the vector. Indexing starts from zero.
Syntax: vec1.component(i) Parameters: The function accepts a single parameter Return Value: It returns element at index i in the vector
Example 1: CPP
#Ruby program for component() method in Vector

#Include matrix
require "matrix"

#Initialize the vector
    vec1
    = Vector[1, 2]

    i
    = 1

#Prints element at index i
      puts vec1.component(i)
Output:
2
Example 2: CPP
#Ruby program for component() method in Vector

#Include matrix
require "matrix"

#Initialize the vector
    vec1
    = Vector[1, 2, 3]

    i
    = 2

#Prints element at index i
      puts vec1.component(i)
Output:
3

Next Article

Similar Reads