havenwood changed the topic of #ruby to: Rules & more: https://ruby-community.com | Ruby 2.7.1, 2.6.6, 2.5.8: https://www.ruby-lang.org | Paste 4+ lines of text to https://dpaste.de/ and select Ruby as the language | Rails questions? Ask in #RubyOnRails | Books: https://goo.gl/wpGhoQ | Logs: https://irclog.whitequark.org/ruby | Can't talk? Register/identify with Nickserv first!
SuperL4g has joined #ruby
fluxAeon has joined #ruby
SuperLag has quit [Ping timeout: 256 seconds]
SuperLag has joined #ruby
SuperL4g has quit [Ping timeout: 256 seconds]
SuperL4g has joined #ruby
SuperLag has quit [Ping timeout: 258 seconds]
xco has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
masticass has quit [Ping timeout: 272 seconds]
masticass has joined #ruby
SuperLag has joined #ruby
ldepandis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
SuperL4g has quit [Ping timeout: 272 seconds]
SuperLag has quit [Ping timeout: 240 seconds]
SuperLag has joined #ruby
bambanx has quit [Quit: Leaving]
crankharder has joined #ruby
jinmiaol1 has joined #ruby
ericm has joined #ruby
BananaDisco has quit [Ping timeout: 244 seconds]
mikecheck has joined #ruby
TomyWork has quit [Ping timeout: 244 seconds]
fluxAeon has quit [Ping timeout: 258 seconds]
crankharder has quit [Ping timeout: 246 seconds]
TCZ has joined #ruby
johnflux has joined #ruby
<johnflux> Hi all. I'm brand new to ruby, but have years of programming experience in general. I'm trying to find a guide that is at a suitable level for me :-)
<johnflux> I'd like to understand what is actually happening when I do, for example, 5.times do |i| print i end
<johnflux> Is there an object "number" or something which the number '5' gets boxed into, and then that number class has a function "times" ?
gaussblurinc1 has quit [Quit: Leaving.]
r29v has quit [Quit: r29v]
<johnflux> likewise, what is "do" ? How should I think of this?
crankharder has joined #ruby
<johnflux> should I think of 'times' as returning some sort of generator, and then "do" is a function of the generator?
imode has quit [Ping timeout: 256 seconds]
<johnflux> Thanks. That first link seems to be simple to answer my question, but skimming it anyway. Second link seems great.
mozzarella has quit [Quit: WeeChat 2.8]
<deimos_> there's also the older edition of the programming ruby book, https://ruby-doc.com/docs/ProgrammingRuby/
<mikecheck> johnflux: 5.class => Integer and 5.methods.include?(:times) => true
mozzarella has joined #ruby
<mikecheck> johnflux: I think do ... end is called a block, like a closure but I'm not sure the difference. times is a method that takes a block. I'm a ruby newb so this might be wrong.
<johnflux> mikecheck: is that the same as 5.responds_to?("times") ?
<johnflux> mikecheck: is that the same as 5.respond_to?("times") ?
b10n1k has quit [Ping timeout: 272 seconds]
<johnflux> "times is a method that takes a block" ah, I thought it was returning an array. So you can't do: puts 5.times for example
<johnflux> hmm, does that make sense in the context of, say: File.open("foo") do ...
<johnflux> It seems unlikely that File.open() is returning a method that takes a block in this example?
<johnflux> mikecheck: I think I might be right:
<johnflux> irb(main):002:0> 5.times
<johnflux> => #<Enumerator: 5:times>
b10n1k has joined #ruby
<johnflux> Idon't know what an enumerator is though
<mikecheck> johnflux: notice the two different return types here: https://ruby-doc.org/core-2.5.0/Integer.html#method-i-times
<mikecheck> johnflux: without an arg, returns Enumerator. with a block passed as arg, does something different.
<mikecheck> johnflux: 5.times seems similar to (1..5).each in other (including ruby) languages: (1..5).each do |i| puts i end
<mikecheck> johnflux: File.open is a method that can take a block. see last two arglists here: https://ruby-doc.org/core-2.5.0/File.html#method-c-open
<johnflux> mikecheck: thank you! That makes a lot more sense now
<johnflux> It explains why I can do: 5.times {|i| print i, " " }
<johnflux> but I can't do: x= 5.times; x {|i| print i, " " }
<johnflux> Is there a good extension for vscode to make it easier to work with ruby?
<mikecheck> johnflux: x = 5.method(:times); x.call { |i| puts i }
<johnflux> mikecheck: curious. you can even do: x.call() and call the other version of that method
ChmEarl has quit [Quit: Leaving]
tubbo has quit [Quit: later skaters]
crankharder has quit [Ping timeout: 264 seconds]
gix has quit [Disconnected by services]
<havenwood> johnflux: solargraph
<johnflux> havenwood: thank you
<havenwood> johnflux: If you don't provide a block, it's common to return an Enumerator. You can then call #each to pass a block.
<havenwood> johnflux: enum = 5.times; enum.each do
<havenwood> johnflux: The #each method is important for Enumerables in Ruby.
dviola has quit [Ping timeout: 246 seconds]
<havenwood> johnflux: The Enumerable module is mixed in to many classes, which each define the #each method.
<TCZ> ah this channel is beaky-free
<havenwood> johnflux: Both Range and Enumerator mix in the Enumerable module, for example. They define #each, so the other Enumerable methods *just work*.
<havenwood> johnflux: You can `include Enumerable` in a class you create and define #each.
<havenwood> johnflux: It's worth studying the Enumerable methods, since they're available in Ruby collection classes like Array, Hash, Set, Range, Struct, Enumerator, etc.
<havenwood> Here's a zoomed out view of the Ruby core object model: https://go.gliffy.com/go/publish/5152080
<havenwood> You can see the classes that mix in Enumerable via the blue line.
<johnflux> havenwood: What does "mix in" mean exactly?
<havenwood> johnflux: Inheritance of classes and "mix in" of modules are the main mechanisms of that type in Ruby. The mixin is either an `include`, `prepend` or `extend`.
<havenwood> johnflux: So like: include Enumerable
<havenwood> johnflux: It's fairly common for classes that include (or "mix in") Enumerable to define an optimized method for one that Enumerable also defines.
<havenwood> johnflux: The `include` means the Enumerable methods won't stomp on those defined in the class, since Enumerable will be lower in the ancestry.
bruce_lee has quit [Ping timeout: 256 seconds]
<havenwood> johnflux: With `prepend`, the Enumerable methods will be in front of those defined in the including class.
<havenwood> johnflux: It's very common to see modules included. That's "mixing in" a module.
<johnflux> Thanks - I have lots to read and google now, thanks.
<havenwood> &>> class Foo; include Enumerable; end; Foo.ancestors
<rubydoc> # => [Foo, Enumerable, Object, Kernel, BasicObject] (https://carc.in/#/r/934g)
<johnflux> In a spec file, I see like: describe Dog do ... end
<havenwood> &>> class Foo; prepend Enumerable; end; Foo.ancestors
<rubydoc> # => [Enumerable, Foo, Object, Kernel, BasicObject] (https://carc.in/#/r/934h)
<johnflux> How should I read this exactly? What is "describe" ?
<havenwood> johnflux: It's a method. You can ask Ruby what it is.
SuperLag has quit [Ping timeout: 265 seconds]
<havenwood> johnflux: defined? describe #=> "method"
<johnflux> > describe
<johnflux> => RSpec::Core::ExampleGroup::Nested_1
<havenwood> johnflux: method(:describe).owner #=> Object
<havenwood> johnflux: To see the receiver of the method, check: method(:describe).owner
<havenwood> johnflux: Or it's source location: method(:describe).source_location
SuperLag has joined #ruby
<havenwood> johnflux: With `describe Dog do`, the `describe` is a method, the `Dog` is the first positional argument, and the `do` is syntax that shows a block is being passed.
<johnflux> that makes a lot of sense :-)
<havenwood> &>> require 'ripper'; Ripper.sexp('describe Dog do; end')
<rubydoc> # => [:program, [[:method_add_block, [:command, [:@ident, "describe", [1, 0]], [:args_add_block, [[:var_ref, [:@const, "Dog", [1, 9]]]], false]], [:do_block, nil, [:bodystmt, [[:void_stmt]], nil, nil, nil]]]]] (https://carc.in/#/r/934i)
<havenwood> &>> RubyVM::InstructionSequence.compile('describe Dog do; end').to_a.last
<rubydoc> # => [:label_0, 1, :RUBY_EVENT_LINE, [:putself], [:opt_getinlinecache, :label_10, 0], [:putobject, true], [:getconstant, :Dog], [:opt_setinlinecache, 0], :label_10, [:send, {:mid=>:describe, :flag=>4, :orig_argc=>1}, ["YARVInstructionSequence/SimpleDataFormat", 2, 7, 1,... check link for more (https://carc.in/#/r/934j)
<havenwood> Those show the S-expression and intermediary VM code.
<johnflux> So somewhere there is some sort of statement that says to alias "describe" to "RSpec::Core::DSL.describe" ?
<johnflux> is it an object method or a class method?
SuperLag has quit [Ping timeout: 256 seconds]
SuperLag has joined #ruby
dviola has joined #ruby
crankharder has joined #ruby
maxxx888 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
TCZ has quit [Quit: Leaving]
SuperLag has quit [Ping timeout: 256 seconds]
SuperLag has joined #ruby
imode has joined #ruby
<havenwood> johnflux: Yes, it's a class method.
<havenwood> johnflux: RSpec code isn't particularly easy to follow. The test framework that ships with Ruby, Minitest, is easier source code to read.
<havenwood> johnflux: The #describe method is created via metaprogramming here: https://github.com/rspec/rspec-core/blob/v3.9.2/lib/rspec/core/example_group.rb#L285
<lucianp> Is Thread.current.object_id sufficient to use as a thread identifier that is unique and unchanged for the duration of a thread?
<lucianp> Or, better yet, is there a way to get the actual thread id?
<havenwood> lucianp: The object id is its unique id. Even if the memory location changes, the id will stay unchanged for the duration of the process.
<havenwood> lucianp: You can name a Thread and use #name, but that's up to you to name.
dviola has quit [Ping timeout: 240 seconds]
<havenwood> lucianp: TL;DR: Yes.
<havenwood> lucianp: But "no," the underlying Thread ID is not exposed by default.
<havenwood> I imagine you could use Fiddle to get at it, but I never have.
pwnd_nsfw has quit [Remote host closed the connection]
SuperLag has quit [Ping timeout: 246 seconds]
braj has joined #ruby
SuperLag has joined #ruby
SuperLag has quit [Ping timeout: 246 seconds]
SuperLag has joined #ruby
braj has quit []
SuperLag has quit [Ping timeout: 265 seconds]
crisfm has joined #ruby
SuperLag has joined #ruby
SuperL4g has joined #ruby
SuperLag has quit [Ping timeout: 272 seconds]
livcd has quit [Ping timeout: 264 seconds]
SuperL4g has quit [Ping timeout: 256 seconds]
<johnflux> I see rspec code like be_thirsty which I think is somehow being autogenerated through inspection - is this correct?
<johnflux> Is this a feature of rspec specifically, or a ruby thing
SuperLag has joined #ruby
lalitmee has joined #ruby
cd has quit [Quit: cd]
maxxx888 has quit [Read error: Connection reset by peer]
maxx88 has joined #ruby
imode has quit [Ping timeout: 258 seconds]
lalitmee has quit [Remote host closed the connection]
wymillerlinux has joined #ruby
_whitelogger has joined #ruby
johnflux has quit []
imode has joined #ruby
bandithijo has joined #ruby
bandithijo has left #ruby ["WeeChat 2.8"]
johnflux_ has joined #ruby
jbeaudoin has quit [Quit: Connection closed for inactivity]
wymillerlinux has quit [Ping timeout: 272 seconds]
maxx88 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
alexherbo2 has joined #ruby
mibr has joined #ruby
mikecheck has quit [Remote host closed the connection]
_whitelogger has joined #ruby
maxxx888 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
<johnflux_> I'm looking at some ruby code and in an rspec file it does: be_thirsty, but a grep for "be_thristy" shows up nowhere else.
crisfm has quit [Quit: WeeChat 2.7.1]
<johnflux_> but there is a thirsty? method
<phaul> that's dynamicly defined. All predicate methods are turned into be_ matchers
<johnflux_> is that done by rspec or by ruby?
<phaul> rspec
<johnflux_> can I see this easily in irb ?
<phaul> You can test that it's indeed defined. I'm not sure how else to see it
gix has joined #ruby
<johnflux_> phaul: thanks
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo2 has joined #ruby
<johnflux_> If I have: def foo() 4 end
<johnflux_> x = :foo
<johnflux_> can I now call method "foo" via x somehow?
<johnflux_> I'm watching a rails video, and he said that a symbol refered to a method, and I don't understand what that means
<phaul> symbols are a bit like constant strings. When you want to refer to a method, you can do that by their name, and that name would be stored in a symbol. But symbols are not necesarrily storing method names, they could store whatever. you can use send to invoke a method by name
<johnflux_> hmm, I can do send(:foo) to call foo()
<phaul> yes you can
<johnflux_> and indeed I can do send(x) here
<johnflux_> phaul: thanks, I think I've got it
<johnflux_> phaul: so there's not really any syntax to actually point to a function, right?
<johnflux_> phaul: callbacks are down by just passing a string or symbol name of that function
<phaul> method would give you an object that actualy points to the method
<phaul> method(:foo) # => a method object
alexherbo2 has quit [Ping timeout: 258 seconds]
<phaul> callbacks are generally done with blocks
<johnflux_> phaul: I'm thinking of the rails "before_action" - I don't know how to find the proper api documentation for that
ellcs has joined #ruby
<phaul> seems it supports both ways, up to the user which one they prefer. It can take method names, it can also take a block
d3bug has quit [Quit: Connection closed for inactivity]
ellcs has quit [Ping timeout: 260 seconds]
maxxx888 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
xco has joined #ruby
cnsvc has joined #ruby
xco has quit [Client Quit]
cnsvc has quit [Ping timeout: 240 seconds]
kristian_on_linu has joined #ruby
alexherbo2 has joined #ruby
jeromelanteri has joined #ruby
ellcs has joined #ruby
b10n1k has quit [Ping timeout: 260 seconds]
conta has joined #ruby
b10n1k has joined #ruby
giorgian has quit [Quit: restart]
giorgian has joined #ruby
imode has quit [Ping timeout: 272 seconds]
SoF has quit [Quit: Ping timeout (120 seconds)]
SoF has joined #ruby
schne1der has joined #ruby
maxxx888 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
ericm has quit [Remote host closed the connection]
schne1der has quit [Ping timeout: 240 seconds]
sh7d has quit [Ping timeout: 256 seconds]
gaussblurinc1 has joined #ruby
cnsvc has joined #ruby
darkstardev13 has quit [Ping timeout: 260 seconds]
cnsvc has quit [Ping timeout: 240 seconds]
chalkmonster has joined #ruby
schne1der has joined #ruby
grimgnr has quit [Quit: WeeChat 2.3]
_aeris_ has quit [Ping timeout: 240 seconds]
_aeris has joined #ruby
_aeris is now known as _aeris_
schne1der has quit [Ping timeout: 256 seconds]
dionysus69 has joined #ruby
sagax has quit [Remote host closed the connection]
crankharder has quit [Ping timeout: 256 seconds]
xco has joined #ruby
chalkmonster has quit [Quit: WeeChat 2.8]
ldepandis has joined #ruby
maxxx888 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
jinmiaol1 has quit [Ping timeout: 260 seconds]
jinmiaol1 has joined #ruby
TCZ has joined #ruby
xco has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
conta has quit [Quit: conta]
alexherbo2 has quit [Ping timeout: 240 seconds]
xco has joined #ruby
cnsvc has joined #ruby
jinmiaol1 has quit [Ping timeout: 240 seconds]
cnsvc has quit [Ping timeout: 240 seconds]
xco has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
cnsvc has joined #ruby
conta has joined #ruby
xco has joined #ruby
xco has quit [Client Quit]
cnsvc has quit [Ping timeout: 240 seconds]
cd has joined #ruby
rcrlst has joined #ruby
Mikaela has quit [Quit: Mikaela]
Mikaela has joined #ruby
xco has joined #ruby
wymillerlinux has joined #ruby
TCZ has quit [Quit: Leaving]
sagax has joined #ruby
rcrlst has quit [Quit: Connection closed]
rcrlst has joined #ruby
rcrlst has quit [Client Quit]
donofrio has joined #ruby
conta has quit [Remote host closed the connection]
maxxx888 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
alexherbo2 has joined #ruby
jinmiaol1 has joined #ruby
chalkmonster has joined #ruby
cnsvc has joined #ruby
d3bug has joined #ruby
ChmEarl has joined #ruby
jinmiaol1 has quit [Ping timeout: 265 seconds]
jinmiaol1 has joined #ruby
trautwein has joined #ruby
davispuh has joined #ruby
trautwein has quit [Ping timeout: 260 seconds]
orbyt_ has joined #ruby
jinmiaol1 has quit [Ping timeout: 246 seconds]
NEETzsche has quit [Quit: ZNC 1.7.4+deb0+bionic0 - https://znc.in]
cnsvc has quit [Remote host closed the connection]
cnsvc_ has joined #ruby
johnflux_ has quit [Ping timeout: 265 seconds]
kristian_on_linu has quit [Remote host closed the connection]
cnsvc_ has quit [Ping timeout: 240 seconds]
schne1der has joined #ruby
schne1der has quit [Client Quit]
conta has joined #ruby
Tempesta has quit [Quit: See ya!]
cloaked1 has joined #ruby
xco has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Tempesta has joined #ruby
TomyWork has joined #ruby
xco has joined #ruby
jeromelanteri has quit [Remote host closed the connection]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
sh7d has joined #ruby
maxxx888 has quit [Read error: Connection reset by peer]
sh7d has quit [Client Quit]
maxxx888 has joined #ruby
sh7d has joined #ruby
wymillerlinux has quit [Ping timeout: 264 seconds]
orbyt_ has joined #ruby
alexherbo2 has quit [Ping timeout: 260 seconds]
wymillerlinux has joined #ruby
alexherbo2 has joined #ruby
TomyWork has quit [Remote host closed the connection]
jinmiaol1 has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ericm has joined #ruby
troulouliou_div2 has joined #ruby
conta has quit [Quit: conta]
troulouliou_div2 has quit [Remote host closed the connection]
rippa has joined #ruby
maxxx888 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
pwnd_nsfw has joined #ruby
banisterfiend has joined #ruby
masticass has quit [Quit: WeeChat 2.8]
cnsvc_ has joined #ruby
yaw has joined #ruby
cnsvc_ has quit [Ping timeout: 240 seconds]
WA9ACE has left #ruby [#ruby]
SuperLag has quit [Ping timeout: 258 seconds]
SuperLag has joined #ruby
orbyt_ has joined #ruby
SuperL4g has joined #ruby
SuperLag has quit [Ping timeout: 260 seconds]
wymillerlinux has quit [Ping timeout: 260 seconds]
mibr has quit [Quit: mibr]
davispuh has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
gato has joined #ruby
davispuh has joined #ruby
maxxx888 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
r3m has quit [Quit: WeeChat 2.9-dev]
banisterfiend has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
SuperL4g is now known as SuperLag
pwl has joined #ruby
jinmiaol1 has quit [Ping timeout: 240 seconds]
jinmiaol1 has joined #ruby
zapata has joined #ruby
banisterfiend has joined #ruby
banisterfiend has quit [Client Quit]
gato has quit [Quit: Connection closed]
r3m has joined #ruby
banisterfiend has joined #ruby
b10n1k has quit [Ping timeout: 246 seconds]
b10n1k has joined #ruby
maxxx888 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
chalkmonster has quit [Quit: WeeChat 2.8]
wymillerlinux has joined #ruby
drincruz has joined #ruby
ericm has quit [Remote host closed the connection]
banisterfiend has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
banisterfiend has joined #ruby
drincruz has quit [Ping timeout: 265 seconds]
imode has joined #ruby
drincruz has joined #ruby
pwl has quit [Quit: WeeChat 2.8]
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
banisterfiend has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
xco has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
xco has joined #ruby
chalkmonster has joined #ruby
dhollinger has quit [Ping timeout: 240 seconds]
dhollinger has joined #ruby
banisterfiend has joined #ruby
drincruz has quit [Ping timeout: 256 seconds]
TCZ has joined #ruby
drincruz has joined #ruby
wymillerlinux has quit [Ping timeout: 264 seconds]
b10n1k has quit [Ping timeout: 272 seconds]
ellcs has quit [Ping timeout: 260 seconds]
b10n1k has joined #ruby
maxxx888 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
teej has joined #ruby
alexherbo2 has quit [Ping timeout: 260 seconds]
chalkmonster has quit [Quit: WeeChat 2.8]
drincruz has quit [Ping timeout: 272 seconds]
ur5us has joined #ruby
zapata has quit [Quit: WeeChat 2.8]
TCZ has quit [Quit: Leaving]
wymillerlinux has joined #ruby
drincruz has joined #ruby
darkstardevx has joined #ruby
drincruz has quit [Ping timeout: 240 seconds]
yaw has quit [Ping timeout: 272 seconds]
dionysus69 has quit [Ping timeout: 256 seconds]
maxxx888 has quit [Read error: Connection reset by peer]
maxxx888 has joined #ruby
ldepandis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ldepandis has joined #ruby
ldepandis has quit [Client Quit]
maxxx888 has quit [Remote host closed the connection]
maxxx888 has joined #ruby
maxxx888 has quit [Remote host closed the connection]
maxxx888 has joined #ruby
maxxx888 has quit [Remote host closed the connection]
maxxx888 has joined #ruby
drincruz has joined #ruby
maxxx888 has quit [Remote host closed the connection]
maxxx888 has joined #ruby
maxxx888 has quit [Remote host closed the connection]
maxxx888 has joined #ruby
drincruz has quit [Ping timeout: 265 seconds]
maxxx888 has quit [Remote host closed the connection]
maxxx888 has joined #ruby