Hidden Features of Ruby

What are the coolest Ruby on Rails features, why choose it?

I blogged in detail about why I love Rails three years ago, but for me for number one cool feature is that it makes developing web applications easy and fun.

Create a hidden folder for logging information in Ruby

I succeeded in creating a hidden folder using a shell command.

module LogEmail 
def log(email)
username = Etc.getlogin
dir = "c:/users/#{username}/log"
if File.exists?(dir)
separator = "[#{Date.today} #{Time.now.strftime('%T')}] ----------"
File.open("#{dir}/email_log.LOG", 'a+') { |s| s.puts(separator, email) }
else
Dir.mkdir(dir)
`attrib +h #{dir}` #<= Creates a hidden folder.
separator = "[#{Date.today} #{Time.now.strftime('%T')}] ----------"
File.open("#{dir}/email_log.LOG", 'a+') { |s| s.puts(separator, email) }
end
end
end

how can ruby optionparser hidden password when user type

To hide your input when asking from input in a ruby program you can use the IO built in class.

require 'io/console'

STDIN.noecho(&:gets

This is directly from the ruby standard library. Use ruby docs IO class for more information. Here is the link

If I had time I would implement it into option parse for you but you can most likely figure it out pretty easily. If not, I will help you tomorrow.

Happy coding!

Hidden features of Groovy?

Using the spread-dot operator

def animals = ['ant', 'buffalo', 'canary', 'dog']
assert animals.size() == 4
assert animals*.size() == [3, 7, 6, 3]

This is a shortcut for animals.collect { it.size() }.



Related Topics



Leave a reply



Submit