Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby string format

time    = 5
message = "Processing of the data has finished in %d seconds" % [time]
puts message
Output => "Processing of the data has finished in 5 seconds"

score = 78.5431
puts "The average is %0.2f" % [score]
Output => The average is 78.54

puts "122 in HEX is %x" % [122]
Output => 122 in HEX is 7a

puts "The number is %04d" % [20]
Output => The number is 0020

names_with_ages = [["john", 20], ["peter", 30], ["david", 40], ["angel", 24]]
names_with_ages.each { |name, age| puts name.ljust(10) + age.to_s }
# Prints the following table
john      20
david     30
peter     40
angel     24
Comment

string formattion ruby

name1 = "John"
name2 = "Mary"
"hello, #{name1}.  Where is #{name2}?"
Comment

PREVIOUS NEXT
Code Example
Ruby :: rails class note reminders 
Ruby :: ruby do something x times 
Ruby :: run method before rails 
Ruby :: ruby prepend string 
Ruby :: Rudy control S 
Ruby :: ruby assign rest of array 
Ruby :: rspec match optional keyword arguments 
Ruby :: rails g sessions controller in rails 
Ruby :: ruby on rails recover data in params with form tag 
Ruby :: ruby mine show all blocks 
Ruby :: self join relationship rails 
Ruby :: dependent destroy, only the foreign key 
Ruby :: rails has_many through source 1 
Ruby :: rails active record to fetch only list of ids 
Ruby :: add extension in ruby tempfile object 
Ruby :: ruby substring 
R :: r sort character number 
R :: r convert string to list of characters 
R :: make a sequence of timeseries per day in r 
R :: how to extract weekday from date in r 
R :: write to csv in r 
R :: R make column of rownames 
R :: how to read multiple csv files from a directory in r 
R :: error installing devtools r 
R :: r first row by group 
R :: finding index of element in r 
R :: how to filter a vector by location in r 
R :: show unique R 
R :: cbind vectors of different lengths r 
R :: R language get help on a dataset 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =