Ruby | Matrix column_count() function Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The column_count() is an inbuilt method in Ruby returns the number of columns in a matrix. Syntax: mat1.column_count() Parameters: The function does not accepts any parameter. Return Value: It returns the number of columns in a matrix. Example 1: Ruby # Ruby program for column_count() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[1, 21], [31, 18]] # prints the number of columns puts mat1.column_count Output: 2 Example 2: Ruby # Ruby program for column_count() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[13, 1, 5], [12, 1, 5], [11, 2, 5]] # prints the number of columns puts mat1.column_count Output: 3 Comment More infoAdvertise with us Next Article Ruby | Matrix row_count() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Matrix-class Similar Reads Ruby | Matrix column() function The column() is an inbuilt method in Ruby returns a vector that has all the elements in the column number col_num. Syntax: mat1.column(col_num) Parameters: The function accepts a parameter col_num which is the column number. Return Value: It returns a vector which has all the elements of column col_ 1 min read Ruby | Matrix component() function The component() is an inbuilt method in Ruby returns the element present at the intersection of i-th row and j-th column. Syntax: mat1.component(i, j) Parameters: The function accepts two parameters i and j which signifies the row_number and column_number. Return Value: It returns the element at mat 1 min read Ruby | Matrix collect() function The collect() is an inbuilt method in Ruby returns the new matrix after performing the operation that is given in the block. Syntax: mat1.collect{|el| operation} Parameters: The function has the parameter as a block which is the operation which is performed on all elements. Return Value: It returns 1 min read Ruby | Matrix row_count() function The row_count() is an inbuilt method in Ruby returns the number of rows in the given matrix. Syntax: mat1.row_count() Parameters: The function does not takes any mandatory parameter. Return Value: It returns the number of rows in the matrix. Example 1: Ruby # Ruby program for row_count() method in M 1 min read Ruby | Matrix column_size() function The column_size() is an inbuilt method in Ruby returns the number of columns in a matrix. Syntax: mat1.column_size() Parameters: The function does not accepts any parameter. Return Value: It returns the number of columns in a matrix. Example 1: Ruby # Ruby program for column_size() method in Matrix 1 min read Ruby | Matrix element() function The element() is an inbuilt method in Ruby returns the element present at the intersection of i-th row and j-th column. Syntax: mat1.element(i, j) Parameters: The function accepts two parameters i and j which signifies the row_number and column_number. Return Value: It returns the element at mat[i][ 1 min read Like