Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby get line from a file

# open the file
File.open('foo.txt') do |file|
  # iterate over each line with its index
  file.each_line.with_index(1) do |line, number|
    puts "#{number}: #{line}"
  end
end
# since we passed a block, the file is automatically closed after `end`
Comment

ruby get line from a file

# open the file
File.open('foo.txt') do |file|
  # iterate over each line
  file.each_line do |line|
    puts line
  end
end
# since we passed a block, the file is automatically closed after `end`
Comment

ruby file get line number

## Like in PHP
## To get line number
__LINE__

## To get file name
__FILE__
Comment

ruby get line from a file

# open the file
file = File.open('foo.txt')

# iterate over each line
file.each_line do |line|
  puts line
end

# close the file afterwards
file.close
Comment

PREVIOUS NEXT
Code Example
Ruby :: ruby intersection of two arrays 
Ruby :: rails form select 
Ruby :: rails excep 
Ruby :: ruby multiline comment 
Ruby :: add timezone in rails 
Ruby :: ruby trim spaces 
Ruby :: rails change date format 
Ruby :: ruby array to string with commas 
Ruby :: rails reset database 
Ruby :: sort hash ruby 
Ruby :: ruby string to symbol 
Ruby :: rename column in db rails 
Ruby :: ruby decimal to hex 
Ruby :: array to hash ruby 
Ruby :: random datetime ruby 
Ruby :: how to add to array ruby 
Ruby :: render partial rails 
Ruby :: ruby hash loop 
Ruby :: ruby conditionals 
Ruby :: format date rails created long 
Ruby :: deep copy and shallow copy in ruby 
Ruby :: rails g migration foreign key optionnal 
Ruby :: check if the substring is present in the column of the record rails console 
Ruby :: ruby clear set 
Ruby :: ruby adding an item to a hash 
Ruby :: comments in ruby grepper 
Ruby :: rails image_tag link size 
Ruby :: time loop start with non zero in ruby 
Ruby :: ruby method 
R :: Drop rows with missing values in R 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =