Уважаемые пользователи Голос!
Сайт доступен в режиме «чтение» до сентября 2020 года. Операции с токенами Golos, Cyber можно проводить, используя альтернативные клиенты или через эксплорер Cyberway. Подробности здесь: https://golos.io/@goloscore/operacii-s-tokenami-golos-cyber-1594822432061
С уважением, команда “Голос”
GOLOS
RU
EN
UA
bitcoinparadise0
7 лет назад

Continuing to Learn Some Ruby

I have been spending some time here and there learning Ruby on Codeacedemy. Currently, I am on the Hashes and Symbols section.

Screenshot.png

Just having some fun and wrote up a little easy script from the example on the site.

Code:
steemians = {
  bitcoinparadise: 65,
  fyrstikken: 72,
  seablue: 61
}

puts "What would you like to do?"
puts "-- Type 'add' to add a steemian."
puts "-- Type 'update' to update a steemian."
puts "-- Type 'display' to display all steemians."
puts "-- Type 'delete' to delete a steemian."

choice = gets.chomp.downcase
case choice
when 'add'
  puts "What steemian do you want to add?"
  name = gets.chomp
  if steemians[name.to_sym].nil?
    puts "What's their rep?
(Type a number 0 to 99.)"
    rep = gets.chomp
    steemians[name.to_sym] = rep.to_i
    puts "#{name} has been added with a rep of #{rep}."
  else
    puts "That steemian already exists! Their rep is #{steemians
[name.to_sym]}."
  end
when 'update'
  puts "What steemian do you want to update?"
  name = gets.chomp
  if steemians[name.to_sym].nil?
    puts "Steemian not found!"
  else
    puts "What's the new rep?(Type a number 0 to 99.)"
    rep = gets.chomp
    steemians[name.to_sym] = rep.to_i
    puts "#{name} has been updated with new rep of #{rep}."
  end
when 'display'
  steemians.each do |steemian, rep|
    puts "#{steemian}: #{rep}"
  end
when 'delete'
  puts "What steemian do you  want to delete?"
  name = gets.chomp
  if steemians[name.to_sym].nil?
    puts "Steemian not found!"
  else
   steemians.delete(name.to_sym)
    puts "#{name} has been removed."
  end
else
  puts "Sorry, I didn't understand you."
end


Here's a little gif of what the script does:

It's not much but I'm still learning and understanding a bit more. I wish I could take more time out of my day to keep at it and be a better coder someday but life has got me busy with a lot these days.

I am amazed by those that know a ton of different programming languages. I only wished I had learned more when I was younger.

About Ruby

Created by Yukihiro “Matz” Matsumoto, he took some of his favorite languages(Perl, Smalltalk, Eiffel, Ada, and Lisp) to form Ruby.

Matsumoto has often said he is:

“trying to make Ruby natural, not simple,” in a way that mirrors life.

Ruby is simple in appearance, but is very complex inside, just like our human body.

Released in 1995, only recently reached mass acceptance in 2006 and is in the top 10 on most of the indices that measure the growth and popularity of programming languages worldwide.

Ruby is free to use, copy, modify, and distribute.

https://www.ruby-lang.org




Image Source



To start trading with bitcoin, checkout:

0
0.061 GOLOS
На Golos с July 2017
Комментарии (4)
Сортировать по:
Сначала старые