<mooff>
it only offers synchronous methods atm, though you can run many bots using threads
<adam12>
aesthetikx: github.com/adam12
<adam12>
mooff: IMHO, I might just look at adding Polyphony. It monkeypatches some of the core libs, so you might not have to modify much existing code.
<adam12>
I do find the Async/Falcon stuff to not be documented _great_.
<adam12>
Ohh yeah. The Rack author is in here. All blame them!
<adam12>
:p
<leah2>
;)
<adam12>
Bacon too, right?
<leah2>
yes
<leah2>
anyone still use that?
<adam12>
What a time to be in Ruby.
<adam12>
I used it ages ago and enjoyed it.
<adam12>
I've just normalized on Minitest, tho minitest isn't necessarily my _favourite_.
<leah2>
yeah
<adam12>
I wish Ruby would have adopted a minitest-like framework into core.
<adam12>
With a _good_ test runner.
<adam12>
It's very muddy lately. test-unit still lives and is used, then there is minitest which is external and good, but at the whim of Ryan who has a preferred style.
<adam12>
We should ship a basic one like the nodejs people are.
<Guest26nakilon>
when I first say config.ru like 15 years ago I wondered what does Russia have to do with it
<Guest26nakilon>
*saw
<Guest26nakilon>
in some sinatra tutorial
<adam12>
LOL
<adam12>
It does make sense on how it's set up. Back then it was all DSL/minimalsym.
<adam12>
Maybe today it would be `Rack do run ... end`
<adam12>
Then keep it .rb
<Guest26nakilon>
I don't mind Ryan's style
<adam12>
Might even be worth a suggestion to rack upstream.
<leah2>
not me! :p
<Guest26nakilon>
what do you guys want from test runner? I heard the gem "m" and probably used it once
<Guest26nakilon>
to specify a line number I guess
<adam12>
Guest26nakilon: Line number. Copy/paste test failures. Easier way to include/exclude. etc.
<adam12>
m is good. I was using minitest-sprint for a while (which is from Ryan)
<Guest26nakilon>
you know what I want?
sickdyd has joined #ruby
<adam12>
leah2: I'm happy for Rack because I remember the time before Rack :(
<Guest26nakilon>
the rspec html formatter to be a standalone converter of junit to html
<Guest26nakilon>
because it's blended in
<adam12>
I wonder why TAP didn't really take off.
<Guest26nakilon>
and the rspec report is the only one existing that does not make eyes bleed
<Guest26nakilon>
and that prevents me to introduce the minitest in production
<adam12>
I want minitest-like with power-assert (without edgecases) and an rspec runner.
<leah2>
adam12: i use it for all my stuff :D
<adam12>
leah2: TAP? iirc bacon supported it.
<leah2>
yes
<leah2>
mostly from bash and C nowadays tho
<adam12>
leah2: Ah interesting. I figured it was dead, so that's good to know.
<leah2>
still common in perl land
sickdyd has quit [Ping timeout: 250 seconds]
<adam12>
Guest26nakilon: I dont' mind Ryans style, but his use of preforce and hoe makes working with his repo's unique. Can't just add the git path to bundler, have to unpack a gemspec if I want it locally, and commits go into preforce manually then back out to git somehow.
<adam12>
Just maybe there's something wrong with the JS.
<leah2>
adam12: no
<Guest26nakilon>
oh, changed wss: to ws: and got connection, now to figure out why it's still pending
<mooff>
*who* is using Perforce?! 🤓
<adam12>
Guest26nakilon: Oh, I see.
<adam12>
Guest26nakilon: I can get your demo to work by adding fill(myColor) to the bottom of messageReceived()
<adam12>
Guest26nakilon: but you're saying maybe teh websocket handshake hasn't finished.
<adam12>
mooff: zenspider
<Guest26nakilon>
oh the circle is changing the color! I guess it's just chrome's feature that it's 0 bytes and pending, but it in fact goes on
<leah2>
i should use bitkeeper ^.^
<adam12>
Guest26nakilon: Oh nevermind. It works without fill(myColor), just super delayed.
<adam12>
leah2: lulz.
<Guest26nakilon>
adam12 not sure why delayed, the draw() is supposed to work in loop
<adam12>
I can understand not wanting to change source systems all the time. I went CVS/SVN/Git.
<adam12>
Guest26nakilon: Maybe latency?
<adam12>
Guest26nakilon: It does work, I was just not patient enough.
<leah2>
adam12: i used almost everything and then git
<Guest26nakilon>
..D
<adam12>
I think git has enough staying power right now, but someone might figure out how to make the git ui a bit less rough.
<Guest26nakilon>
speaking about the async documentation, I added "p 1" within $connections.each but it does not go to my stdout
<adam12>
Is stdout buffered
<Guest26nakilon>
I need to debug but I foresee the struggling
<adam12>
Try setting it to sync if not already. $stdout.sync = true
<adam12>
`1` might not be enough to flush the buffer.
<Guest26nakilon>
sec
<adam12>
bbiaf lunch :)
<Guest26nakilon>
oh
llua has joined #ruby
<Guest26nakilon>
it's because I had temp.rb in sublime opened
<Guest26nakilon>
_--
<adam12>
LOL
<Guest26nakilon>
bon appeti
<Guest26nakilon>
I want to try use p5js instead of taking curses from the shelve
<Guest26nakilon>
thanks for hints, I now can proceed
<Guest26nakilon>
I imagine responding with graphics primitives with ruby lambda __id__s attached
<Guest26nakilon>
not sure about memory though; need to keep the lambdas attached to some objects; or using classes and tuples of obj.__id__ and method name
szkl has quit [Quit: Connection closed for inactivity]
<Guest26nakilon>
"to make the git ui a bit less rough." -- I see no need
<Guest26nakilon>
those who don't want or can't deal with it can gtfo
<Guest26nakilon>
it takes just few days of patient working in a team that knows better, and you'll be ok with it
BazzaBazaa has quit [Ping timeout: 245 seconds]
_ht has joined #ruby
BazzaBazaa has joined #ruby
crespire has joined #ruby
sickdyd has joined #ruby
crespire1 has quit [Ping timeout: 250 seconds]
crespire1 has joined #ruby
crespire has quit [Killed (NickServ (GHOST command used by crespire1))]
BazzaBazaa has quit [Remote host closed the connection]
sickdyd has quit [Ping timeout: 240 seconds]
donofrio has joined #ruby
donofrio has quit [Ping timeout: 240 seconds]
desnudopenguino has quit [Ping timeout: 248 seconds]
donofrio has joined #ruby
llua has quit [Quit: <Rudolph> shell code is what greycat reads to kids when he tucks them in]
sickdyd has joined #ruby
llua has joined #ruby
Prodigy has joined #ruby
donofrio has quit [Ping timeout: 256 seconds]
sickdyd has quit [Ping timeout: 250 seconds]
blades7 has joined #ruby
blades7 has quit [Read error: Connection reset by peer]
donofrio has joined #ruby
Guest26nakilon has quit [Quit: Client closed]
roadie has joined #ruby
johnjaye has quit [Read error: Connection reset by peer]
<aesthetikx>
you either need something do |block| ; end
<aesthetikx>
or,
<aesthetikx>
something { |block| }
<aesthetikx>
but not moth
<aesthetikx>
both*
<aesthetikx>
in your case, you probably want "Resolv::DNS.open { |dns| ..... }
<johnjaye>
what is the |block| thing called
<aesthetikx>
a block argument
<johnjaye>
i see
<aesthetikx>
3.times { |i| puts i }
<aesthetikx>
will print i three times
<aesthetikx>
methods can 'yield' items to a block an arbitrary number of times, and the block will run each time with the argument in between the |pipes|
<aesthetikx>
typically rubyists will use the braces form for one liners, but for longer stuff:
<aesthetikx>
3.times do |i|
<johnjaye>
not sure what you mean by arbitrary. usually it's just to go over a collection right
<aesthetikx>
puts i
<aesthetikx>
end
<aesthetikx>
yes, but you can have methods that only yield once, for example a callback
<aesthetikx>
or File.open { |f| # the file is open here but this is only called once, the file is automatically closed after the block }
<johnjaye>
isn't that the opposite of conventional notation
<johnjaye>
normally the whole point of braces is a multiline block
<aesthetikx>
the opposite I believe
<johnjaye>
so ruby is cool and doesn't play by the rules. i dig it
<aesthetikx>
lol you could say that , yes
<johnjaye>
i thought it was some weird usage of set builder notation
<johnjaye>
like A = { x | x is blue }
<aesthetikx>
a lot of people get confused because they think they are looking at | | as an absolute value or something, but its just how the block args are written
<aesthetikx>
yeah
<aesthetikx>
nope
<johnjaye>
it does look very odd yeah.
<aesthetikx>
would almost be clearer if it was parenthesis, but that is what 'smalltalk' did, and thats where its from
<johnjaye>
why does it have to be enclosed though
<johnjaye>
why not ,arg or ;arg
<aesthetikx>
if you use a stabby lambda you get my_fn = ->(one, two, three) { # do something }
<johnjaye>
the -> is code for lambda?
<aesthetikx>
shorthand yeah
<aesthetikx>
there can also be multiple args, e.g. some_collection.each.with_index { |the_thing, the_index| # ... }
<johnjaye>
lambda is probably an unfortunate choice of letters anyway. but meh
<johnjaye>
oooh really
<henk>
aesthetikx: oooh, I see, thanks
<aesthetikx>
yup lmk if you get stuck again
friendlypunk has joined #ruby
donofrio has quit [Ping timeout: 268 seconds]
donofrio has joined #ruby
infinityfye has quit [Quit: Leaving]
<johnjaye>
aesthetikx: hope you don't mind if i ping you
<johnjaye>
but i forgot to ask something
<aesthetikx>
all good
<aesthetikx>
whats up
<johnjaye>
in ruby is there no way to access a class or object variable directly?
<johnjaye>
the tutorial i read implied that but it's a bit strange to me
<aesthetikx>
hmm elaborate?
<johnjaye>
in java you can make an object field public or private
<johnjaye>
if public you can set it directly
<aesthetikx>
oh I see
<johnjaye>
as in a.x = 2, a.y = 3
<johnjaye>
or just use it. i = a.x + 7
<aesthetikx>
if you want that behavior, you can use 'attr_accessor :the_thing'
<aesthetikx>
e.g. class Pet; attr_accessor :name; end
<johnjaye>
oh attr_accessor is literal?
<aesthetikx>
dog = Pet.new; dog.name # => nil ; dog.name = "Jim"; dog.name #=> Jim
<aesthetikx>
yeah its actually a method, that makes two more methods, let me explain
<aesthetikx>
so, instances of a class have instance variables, which you may have seen, they look like @name (they have a '@' prefixed)
<aesthetikx>
these are private by default
<aesthetikx>
so, by convention you would write class Pet; def name; @name; end; end (sorry for the single line, but you get the idea)
<johnjaye>
yeah. in java you declare those directly. like class Pet; string name; end
<johnjaye>
but in ruby examples it's only in the constructor
<aesthetikx>
and then you would also write class Pet; def name=(new_name); @name = new_name; end; end; for hte 'setter'
<johnjaye>
right.
<aesthetikx>
attr_accessor just defines both of those methods for you
<johnjaye>
i saw that in the tutorial
<johnjaye>
oh ok
<aesthetikx>
there is also "attr_reader" which just gives you the public method to get, and "attr_writer" which just gives you the setter
<johnjaye>
ah ok. yeah when i put () at the end it still runs
<johnjaye>
the ruby way of omitting the () for method calls is very odd
<aesthetikx>
its fun :)
hrberg has joined #ruby
<aesthetikx>
but yeah if you aren't familiar it can be confusing, becuase its hard to tell what is a method
<aesthetikx>
but pretty much everything is a method, so yeah
<mooff>
*weekly thought wishing classes could be imported as modules*
<johnjaye>
what about for a class variable
<johnjaye>
like the @@i=1 type thing
<aesthetikx>
typically not used as much, but those are "@@thing", yes
<johnjaye>
can i not define them outside of the constructor?
<johnjaye>
or an object methodi mean
<aesthetikx>
so, for methods, you use "def self.the_class_method" , e.g. prefix the word self
<johnjaye>
java concept maybe coming in here. in java you can have a static variable i think it's called? where it's basically just callable from any object at all
sickdyd has joined #ruby
donofrio has quit [Ping timeout: 250 seconds]
<aesthetikx>
you can do "def self.whatever" for a class method;
<johnjaye>
oh. then it's callable even if there areno objects?
<aesthetikx>
for class variables you can just say "@@static_variable = '4'" right in the class body
<aesthetikx>
yes
<johnjaye>
like Pet.print("something")
<aesthetikx>
yup call it right on the class, Pet
<johnjaye>
i tried @@i=2 in the class body but it didn't work
<johnjaye>
or at least i couldn't print it out
<johnjaye>
do i need an accessor too?
<aesthetikx>
for class variables I think no, they are treated as sort of public
<mooff>
@@ variables are specific
<johnjaye>
how do i get at it then
<johnjaye>
i get undefined method i
<aesthetikx>
I think you should be able to do class Pet; @@i = 1; end; puts Pet.i # > 2
<johnjaye>
if i do x.i
<aesthetikx>
# => 1 *
<mooff>
they are stored on the module you're currently working in, lexically
<aesthetikx>
oh, if you need to get at it from an instance instead of the class, youw ould have to write like def i; self.class.i; end
<johnjaye>
hrm
<johnjaye>
i was trying something like class Pet; @@i=2; end; puts Pet.i and it gave error
<johnjaye>
this is in a file
<aesthetikx>
I think that sould work, i just tried it
<aesthetikx>
huh
<mooff>
they're scoped to your current nested module, as in the module for your nearest class / module keyword
sickdyd has quit [Ping timeout: 250 seconds]
<johnjaye>
i get NoMethodError
<aesthetikx>
oh I'm dumb yeah ignore me
<johnjaye>
mooff: why did it work just no but not for me? i'm confused
<aesthetikx>
tbh class variables are so rarely used that I honestly don't know much about how they work, despite using ruby for like 15 years hahah
<johnjaye>
yeah. i would think a class method would be more common. and for that i need self
<johnjaye>
i think?
<johnjaye>
so like File.read
<johnjaye>
how do i define that again. sorry if i misunderstood
<aesthetikx>
yeah class File; def self.read #... ;end
<mooff>
the main thing you're thinking about is @foo aye
<mooff>
that's the one you want
<mooff>
it works exactly the same way whether self is a class object or any other object
<johnjaye>
o i see that works.
<mooff>
and totally separate to @@ vars
<johnjaye>
but on the @@ vars thing
<mooff>
the @@ vars are lexical module vars
<mooff>
that's the clearest way I can think to put it
<mooff>
they are found and set based on the nearest class or module you've opened
<mooff>
and the scope for that can't be set by anything other than "class" and "module" keywords
<mooff>
they must have been set to at least once before they're read, or Ruby raises a NoNameError
<mooff>
I use @@foo ||= sometimes which gets around it
sickdyd has joined #ruby
<mooff>
they're nice but specific in that way
<mooff>
and with the specific scope
johnjaye has quit [Ping timeout: 250 seconds]
panella32 has joined #ruby
panella32 has quit [Client Quit]
<aesthetikx>
johnjaye, there is one secret; you can do class Pet; class << self; attr_accessor :something; end; end if you want Pet.something = 1
<aesthetikx>
although that syntax is something that you will need more experience with ruby to actually understand meaningfully
<aesthetikx>
otherwise in general you can only access @@something within other class or instance methods of that class
panella32 has joined #ruby
johnjaye has joined #ruby
panella32 has joined #ruby
<panella32>
Hi currently I'm having a :movies table and a :people table which have many-to-many relationship. I am going to add a new column "director_id" to :movies table. Using a migration containing the following line I achieved the goal and now it is working as expected:
<aesthetikx>
that way you will get some_movie.director.movies # => [some_movie, ...]
sickdyd has quit [Ping timeout: 250 seconds]
<panella32>
sorry for the too long delay, need to restart the whole thing
<panella32>
now i get RecordInvalid: Validation failed: Director must exist
<aesthetikx>
If you don't need a director, I think you can say ", optional: true"
<aesthetikx>
in newer versions of rails, belongs_to associations are required by default I believe
<aesthetikx>
so "belongs_to :director, class_name: 'Person', optional: true"
<panella32>
Maybe it's looking for a class like "Director" and can't find it?
<aesthetikx>
I believe that validation is happening for new records being created, but I think "optional: true" will allow you to have a nil director_id
<johnjaye>
aesthetikx: i was disconnected. did you reply to me
<aesthetikx>
i did
<aesthetikx>
sorry
<johnjaye>
i didn't see it i mean
<aesthetikx>
Add "optional: true"
<aesthetikx>
to your "belongs_to"
teclator has joined #ruby
<aesthetikx>
in newer versions of rails, belongs_to is required by default for new records; optional: true will allow you to have a nil director_id
<johnjaye>
yes i didn't understand your pet example
<johnjaye>
class Pet @@i=2 end puts Pet.i
<johnjaye>
why does this fail
_ht has quit [Quit: _ht]
<aesthetikx>
panella32 glad to hear it!
<aesthetikx>
johnjaye I think class variables are only accessible to that classes' class methods or instance methods;
<johnjaye>
meaning the only way to access it would be with a method?
<aesthetikx>
if you want that behavior you can say class Pet; class << self; attr_accessor :i; end; end which we could go over more later, that goes into some advanced ruby usge
<johnjaye>
ok. i tried adding def i / i / end to the class but that doesn't work either
<aesthetikx>
class Pet; def self.i; @@i; end; def self.i=value; @@i = value; end; end; will also work
<johnjaye>
oh i see. Pet.i is not allowed. I can only create a specific pet object and call it through that
<aesthetikx>
right, with a regular 'ol "def i" yeah
<johnjaye>
i learned oop in java so that's why i'm asking things like this.
<aesthetikx>
they are valid questions
<aesthetikx>
ruby is a mix of OOP, functional, perlisms, smalltalk, so there is usually a 'ruby way' of doing things that isnt 1:1 with other langs
<johnjaye>
well for example say you had class Shape and needed to put pi=3.14 as a static class member, that would be an example coming to mind.
<johnjaye>
because you want it available to every object of the class
<johnjaye>
does it have good concurrency or is that more of an erlang thing
<aesthetikx>
in that case, you would probably want an actual constant;
<aesthetikx>
class Shape; PI = 3.14; end
<aesthetikx>
Shape::PI # => 3.14
<aesthetikx>
variables written in all caps like that are constants
donofrio has joined #ruby
<johnjaye>
i guess you sort of have that already though
<johnjaye>
so maybe in super elite oo theory you don't need class variables
<aesthetikx>
concurrency is a mixed bag depending on who you ask,
<johnjaye>
a constant has different visibility than a member?
<aesthetikx>
there are some new things added in ruby 3.x that are pretty nice for both concurrency and parallelism
<aesthetikx>
constants are public but need to be accessed with :: (namespace resolution operator) outside the class, or just 'PI' if it is in scope already
johnjaye has quit [Ping timeout: 265 seconds]
<aesthetikx>
panella32 I still haven't seen the others, although it is on my list, is it good?
johnjaye has joined #ruby
<johnjaye>
hmm my connection seems unstable. guess i will bow out for now
<johnjaye>
thanks for answering my questions though
<panella32>
aesthetikx I was a kid when I watched it back in the day and idk why but I loved the kind of atmosphere and stories. Still it's a nostalgia kind of thing for me.
<aesthetikx>
that way you could do some_person.movies # => all the movies they workded on through movie people,
<aesthetikx>
or some_person.directed_movies # => the movies they directed
<aesthetikx>
in addition to that, you might want to add "dependent: :nullify",
<aesthetikx>
so that if a Person is destroyed who was a director, the director_id on those Movies would be nil (instead of I think you would end up with a foreign key violation or something)
<aesthetikx>
ofc, if you don't need to access movies / directors like that in your app, you don't actually need the associatoins. In this case it would probably be good to have it either way though, to have rails clean up the foreign keys if a person is destroyed regardless
Pixi` has joined #ruby
nektro_ has joined #ruby
<panella32>
I see, great point thanks! I'm not sure why but I'm still getting : unknown column 'movies.person_id'
<aesthetikx>
sure,
FetidToot4 has joined #ruby
<aesthetikx>
I think it may want you to specify "foreign_key: :director_id", on that has_many
<aesthetikx>
normally that wouldn't be needed, but in this case because it is the Person class it is by default assuming that the foreign_key will be called person_id, and you ahve to tell the association that you have a column called director_id
<aesthetikx>
I can never remember if that is needed or not, I always think that "inverse_of: :director" should automatically change the foreign key, but it doesn't
kenichi_ has joined #ruby
shokohsc4 has joined #ruby
Shell- has joined #ruby
Fridtjof_ has joined #ruby
catphish_ has joined #ruby
dstein64- has joined #ruby
leftylin1 has joined #ruby
Shell- is now known as Shell
Shell has quit [Killed (copper.libera.chat (Nickname regained by services))]
johnjaye has quit [Ping timeout: 250 seconds]
asio_ has joined #ruby
genpaku_ has joined #ruby
tomtmym has quit [Quit: Gone.]
zak1 has joined #ruby
peder_ has joined #ruby
finstern1s has joined #ruby
<panella32>
Tried the "foreign_key: :director_id"" option and now it's working great! Thanks you must be a ActiveRecord specialist aesthetikx! I wish I could had a teacher like you to learn ror from!
kenichi_ has quit [Changing host]
kenichi_ has joined #ruby
<aesthetikx>
awesome, I think you have actually covered most of the various options for 90% of relations
<aesthetikx>
I'm here most of the time if you need
<aesthetikx>
this may or may not be needed for your app, but another approach to modelling your data could be to have a kind of 'role' on movies_people,
<aesthetikx>
e.g. Movie has_one :director, through: :movie_people, -> { merge(MoviePeople.director) }
<panella32>
It is a blessing to have you here, I am really happy about it!
<aesthetikx>
or something like that, I cant' do it off the top of my head, but anyway its an option to dig into if you are super bored.
<aesthetikx>
seems liek what you have is good for now though
<panella32>
Not a fan of docs but I'll check it out lol
<panella32>
Actually I had that in mind too!
<aesthetikx>
yeah I get that but the docs aren't actually that bad
<aesthetikx>
in this case anyway
donofrio has quit [Ping timeout: 240 seconds]
<aesthetikx>
yeah if you have a role (probably an Enum, look that up if you haven't seen that before, those are great in rails),
<aesthetikx>
then you could make a bunch of associations without changing your schema, for other types of things e.g. screenwriter or something
dstein64 has quit [*.net *.split]
FetidToot has quit [*.net *.split]
shokohsc has quit [*.net *.split]
Fridtjof has quit [*.net *.split]
nektro has quit [*.net *.split]
ox1eef_ has quit [*.net *.split]
asio has quit [*.net *.split]
Pixi has quit [*.net *.split]
leftylink has quit [*.net *.split]
catphish has quit [*.net *.split]
peder has quit [*.net *.split]
mooff has quit [*.net *.split]
finsternis has quit [*.net *.split]
kenichi has quit [*.net *.split]
z4kz has quit [*.net *.split]
genpaku has quit [*.net *.split]
joast has quit [*.net *.split]
peder_ is now known as peder
FetidToot4 is now known as FetidToot
dstein64- is now known as dstein64
shokohsc4 is now known as shokohsc
finstern1s is now known as finsternis
<panella32>
yeah I was actually going to add such column but skipped it for later but it's a good idea..
<aesthetikx>
yeah thats a later idea for a later time
John_Ivan has joined #ruby
mooff has joined #ruby
<aesthetikx>
it is often the case in 'enterprise' or productioney systems where things like 'A movie has a director' fails as soon as there is some movie out there with two director credits or something
<aesthetikx>
always super fun to go from N=1 to N=M
<aesthetikx>
modeling human relationships especially can be hard
teclator has quit [Ping timeout: 250 seconds]
roadie has quit [Ping timeout: 248 seconds]
<panella32>
I agree. My project actually it's a simplified version of TMDB and I just ignored that case because as you said it'd bring too much unnecessary complication to my basic project as I am just gonna learn though developing the app..
<panella32>
not directly related but is there any specific course or code learning website you generallyrecommend for lower intermediate ror devs?
<aesthetikx>
Back in the day I really liked "destroy all software" and "railscasts" but both of those are somewhat outdated now
<aesthetikx>
let me see
<aesthetikx>
there is someone on yt that is pretty good
<aesthetikx>
but other people will probably have better input on that one than me, i learned a long long time ago
<aesthetikx>
you could make an account or follow some people on ruby.social (im there) or rails.social etc.
joast has joined #ruby
<aesthetikx>
ruby.social I mean, not sure what rails.social is, seems private although that kobaltz guy has an account there somehow, maybe its his instance
<aesthetikx>
im off for a bit ttyl
<panella32>
Sure I do check it out. Let me thank you again!