Превосходство Ruby

Ruby is better than Python for Unix-like system administration

Ruby vs JavaScript (Why ruby)

  • продуманный дизайн языка (всякие там итераторы, блоки кода)
    • лаконичный синтаксис
  • фичи для тестирования кода в языке
  • %{...} из коробки

Why Ruby?

  • One file, no dependencies
  • Works on any system with Ruby (macOS has it built-in)
  • Fast enough for thousands of directories
  • Easy to hack on

try - fresh directories for every vibe

Классные пакеты для Ruby

  • Rake - мейкфкайл на руби. Можно задавать команды и последовательность из них
    • [[ https://github.com/ruby/rake|гитхаб ]]
  • Rack - прослойка для сервера (аутентификации, логирование) ( [[ https://www.rubyguides.com/2018/09/rack-middleware/|подробнее ]])
  • standardrb - линтер для руби
    • [[ https://github.com/standardrb/standard|гитхаб ]]

Документация для Авроры

https://gitverse.ru/aurora_devs/KnowledgeBase - сайтик на [[ Jekyll ]]

What exactly to use Ruby for?

reddit тред

  • Well putting aside Rails as a no-brainer, Ruby’s still a (great IMO) general purpose language. From CLI scripts to automation (Rake is useful here), GUI (with Glimmer), and more. You could use it for anything you’d want to build really, but of course the ecosystem of libraries may be somewhat limited depending on your use-case. To give you some examples: - Fusuma is an app for “Multitouch gestures with libinput driver on Linux”, one that I really like and use a lot. And guess what, it’s made on Ruby! - Sonic-Pi is a “Free code-based music creation and performance tool.” that uses Ruby as scripting language. - DragonRuby is a “A cross-platform game engine” that uses Ruby as the scripting language too! - lolcat give it a read lol. There are more stuff surely but I don’t want to make an awesome list. The main thing is though. Just use it to build stuff you like, play with it, experiment and learn. The things you’ll learn with Ruby will be useful for learning other languages later on, specially OOP ones. P.S. If you’re into embedded then you’d like MRuby.

  • CLI apps and glue scripts. Perfect for that. The built in OptionParser is very full featured and file I/O is super easy as is basic HTTP scripting.

  • Script your system! Ruby excels at this. If you need to automate any system job or sysadmin task, Ruby is a great choice.

  • Ruby is great for general scripting. Wherever you have a shell script you can do better with Ruby.

    Ruby has way better iteration. Ruby has full set of file operations (things like copying, renaming, deleting, changing permissions, etc.). Ruby has built-in Open3 library for all you external tools with much more granular control if you want it. Ruby has Find library for recursive search in directories. It has Rake for build scripts. It’s like make, but with sane syntax and full power a general programming language language at hands.

    Shell scripts are full of weird edge cases, syntax gotchas, and inconsistencies between shells. I can not put into words how much Ruby is better than shell scripts.

В сравнении с python

One factor alone that irritates me above all else in python: OOP methods require an extra parameter “self” to be declared. So the instance method signature may have 2 params, but when you call it, it has 1. It’s not “DRY” (Don’t Repeat Yourself). They go to all the trouble of cleaning things up by using whitespace to get rid of ends or brackets… (I didn’t like at first but I can live with that) but end up typing extra syntax.

   class Parrot:
       # instance attributes
       def __init__(self, name, age):
           self.name = name
           self.age = age
       # instance method
       def sing(self, song):
           return "{} sings {}".format(self.name, song)
       def dance(self):
           return "{} is now dancing".format(self.name)
   # instantiate the object
   blu = Parrot("Blu", 10)
   # call our instance methods
   print(blu.sing("'Happy'"))
   print(blu.dance())

In this example (from https://www.programiz.com/python-programming/object-oriented-programming) sing has 2 params defined, but is only called with 1. I know how it works, but it’s just jarring. self self self self self

It just looks like OOP was tacked on to a procedural language - let’s just pass in an extra param of the object the code works on. That’s how it’s done in C (perl too? it’s been a while) It also means every reference to the object data must be explicitly stated, hence the need for “self.name” above.

In ruby, I can just assume that if I’m inside an instance method, I have access to instance variable and instance methods, most of the time without having to use a self reference (There are times where it should be used to prevent confusion)

So the ruby equivalent:

   class Parrot
       attr_accessor :name, :age
       def initialize(name, age)  # 2 params
           @name = name
           @age = age
       end
       def sing(song)             # 1 param
           "#{name} sings #{song}"
       end
       def dance                  # no params
           "#{name} is now dancing"
       end
   end
   blu = Parrot.new("Blu", 10)  # 2 params
   puts blu.sing("'Happy'")     # 1 param
   puts blu.dance               # no params, parens not needed

It’s just easier to read, and the number of params match up. Ruby is just a joy to read and write

Notes mentioning this note

There are no notes linking to this note.


Here are all the notes in this garden, along with their links, visualized as a graph.