Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby name of current file

# /rails_app_generator/cli/profile.rb

# Name of current program file
puts __FILE__					# => /rails_app_generator/cli/profile.rb
puts File.dirname(__FILE__)		# => /rails_app_generator/cli
puts File.basename(__FILE__)	# => profile.rb

# Name of starting program file
puts $0							# => exe/rag
Comment

ruby get file name

path = "/path/to/xyz.mp4"

File.basename(path)         # => "xyz.mp4"
File.extname(path)          # => ".mp4"
File.basename(path, ".mp4") # => "xyz" OR
File.basename(path, ".*")   # => "xyz"
File.dirname(path)          # => "/path/to"

# Alternative to File.extname(path) for multiple extension periods
def full_extname(path)
  ext = File.basename(path).split('.', 2)[1]
  ext.nil? ? '' : ".#{ext}"
end

full_extname('/path/to/xyz.mp4')				# => ".mp4"
full_extname('/path/to/xyz.my.custom.ext.mp4')	# => ".my.custom.ext.mp4"
full_extname('/path/to/xyz')					# => ""
Comment

PREVIOUS NEXT
Code Example
Ruby :: if contains ruby 
Ruby :: find path of module in ruby 
Ruby :: ruby iterate over array 
Ruby :: activerecord less than 
Ruby :: how to down a particular migration in rails 
Ruby :: contains ruby array 
Ruby :: rails update without callback 
Ruby :: how to force exit server in rails 
Ruby :: rails find_by order limit 
Ruby :: function is uninitialized constant ruby 
Ruby :: httparty SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate) (OpenSSL::SSL::SSLError) 
Ruby :: ruby match word in string 
Ruby :: rails activerecord to hash 
Ruby :: ruby sort array numerically 
Ruby :: attr_accessor ruby 
Ruby :: rails convert image to base64 
Ruby :: ruby hash delete 
Ruby :: ruby check if constant exists 
Ruby :: What does inject in ruby do 
Ruby :: true sting to true in rails 
Ruby :: select tag . Default value rails 
Ruby :: rails subdomain 
Ruby :: add index in rails 
Ruby :: insert element in the middle of an array ruby 
Ruby :: Rudy control S 
Ruby :: add two numbers ruby 
Ruby :: self join relationship rails 
Ruby :: merge two binary trees sloved in ruby 
Ruby :: rails group every 10 items in array 
R :: update r from rstudio 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =