You are not logged in.
Sorry for a Ruby package related post. But there's something missing particularly from extra/ruby.
I have been using the SimpleDelegator class for various things. But I noticed, Ruby 2.7 (ArchLinux x86_64) doesn't come with the SimpleDelegator class (no Delegator either).
My program:
#!/usr/bin/ruby -w
class OutputDecorator < SimpleDelegator
def puts(*args)
STDOUT.write "Hello #{args.join}... It's Ruby #{RUBY_VERSION} #{RUBY_PLATFORM}\n"
end
end
$stdout = OutputDecorator.new($stdout)
$stdout.puts('Sourav')
$stdout = $stdout.__getobj__
$stdout.puts('Sourav')Running with:
RVM Ruby 2.6.3:
> ~/.rvm/rubies/ruby-2.6.3/bin/ruby p.rb
Hello Sourav... It's Ruby 2.6.3 x86_64-linux
SouravRVM Ruby 2.7.0-preview1:
~/.rvm/rubies/ruby-2.7.0-preview1/bin/ruby p.rb
Hello Sourav... It's Ruby 2.7.0 x86_64-linux
Souravextra/ruby 2.7.0:
> ruby p.rb
Traceback (most recent call last):
p.rb:2:in `<main>': uninitialized constant SimpleDelegator (NameError)But this shouldn't be that way. SimpleDelegator should be there:
Where is SimpleDelegator in Ruby 2.7?
Last edited by Sourav (2020-02-28 22:11:15)
Offline
SimpleDelegator is defined in 'delegate.rb'. Thus to make your example working you need to add "require 'delegate'" before using the class.
#!/usr/bin/ruby
require 'delegate'
class OutputDecorator < SimpleDelegator
def puts(*args)
STDOUT.write "Hello #{args.join}... It's Ruby #{RUBY_VERSION} #{RUBY_PLATFORM}\n"
end
end
$stdout = OutputDecorator.new($stdout)
$stdout.puts("Sourav")
$stdout = $stdout.__getobj__
$stdout.puts("Sourav")Why the other distros do not need that 'require'? I do not know honestly but I suspect they pre-load a lot of crap at the script start.
Last edited by anatolik (2020-02-29 05:07:36)
Read it before posting http://www.catb.org/esr/faqs/smart-questions.html
Ruby gems repository done right https://bbs.archlinux.org/viewtopic.php?id=182729
Fast initramfs generator with security in mind https://wiki.archlinux.org/index.php/Booster
Offline
Why the other distros do not need that 'require'? I do not know honestly but I suspect they pre-load a lot of crap at the script start.
According to the OP's link, someone responded that older versions of rubygems, by sheer coincidence, happened to require 'delegate', and since rubygems is automatically loaded at startup, the 'delegate' library was automatically available for free.
Since Arch Linux packages a newer version of rubygems, the new rubygems version "broke" this simple script which did not list its dependencies properly.
And the comparison to archlinux ruby 2.7.0 was rvm ruby 2.7.0-preview1 but I simply cannot fathom how one could compare a preview to a final release, but that is a whole separate issue.
...
Incidentally, *why* does ruby do this at all? Does a library get loaded into global scope once loaded? In python, if you import a module in one file, it ends up cached in sys.modules for anything to use, but it's only available on a per-file level to things which also imported it. And it's not just python which behaves in this, frankly, sane manner. If you #include <foo.h> in a C source file, then the functions defined in foo.h are only available to that *one* translation unit, not *every single C file in the entire project directory*.
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline