kurko_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kujira has joined #ruby
<apeiros>
anything which is callable is a method, no matter how it looks. and methods can be uppercase.
<apeiros>
"global" methods are (if properly done) instance methods in Kernel, marked as module_function (i.e. also available via `Kernel.`, c.f. `puts` and `Kernel.puts`)
jottr has quit [Ping timeout: 272 seconds]
asphyxia has quit [Ping timeout: 272 seconds]
<mkroman>
eh? by that assumption, do you mean that URI = URI.parse should be def Kernel.URI(…); …; end?
<apeiros>
and no, it should be (and looks like it was) `module Kernel; module_function def URI …; end; end`
<apeiros>
not really a style battle. it's what core does and it's got good reasons to do it this way.
<mkroman>
huh, I never realized this detail and will look it up
<al2o3-cr>
you don't need module_function in Kernel do you?
<apeiros>
whether URI() is == URI.parse depends on the definition of Kernel#URI. would make sense. but there doesn't need to be an equivalent class method. f.ex. I'm not aware of an equivalent for Kernel#Integer
<apeiros>
al2o3-cr: it's not about "need", it's about "should".
<al2o3-cr>
why should it?
<mkroman>
I kind of just assumed URI had an overload of URI.call(…)
<apeiros>
a) make it private in the instance (which makes you not fuck up method_missing for everybody)
<apeiros>
b) make it available globally, e.g. even BasicObject instances via ::Kernel.your_method
<apeiros>
mkroman: just looked at the source. Kernel#URI != URI.parse
<apeiros>
URI.parse is a part of it, but it does a bit more.
<al2o3-cr>
apeiros: i see, thanks for the clarification.
<apeiros>
(not much, though)
<apeiros>
al2o3-cr: yw
<mkroman>
however, I still want to argue that providing URI(…) and providing URI.parse(…) is unnecessarily complex to a new rubyist - I have several years of experience with Ruby and you just made me realize it's not as simple as a URI.call overload
<apeiros>
mkroman: I concur.
<apeiros>
applies to all capitalized kernel methods IMO
<mkroman>
yep
<mkroman>
but....
<apeiros>
and honestly, even Kernel should only be optionally included.
houhoulis has quit [Remote host closed the connection]
<mkroman>
“the ruby way” is kind of to make most things as a DSL as possible
<mkroman>
to some degree, of course
<apeiros>
gotta get some sleep. it's already 2b:00 (or is it written 2:00b?)
<mkroman>
and in some cases I've resorted to D = URI('some_uri') just for the shorteness of it, which is nice, but it's ridiculously complex for what it is.
* apeiros
now ponders looking whether iso8601 has standardization for this shit
<mkroman>
Sun Oct 28 02:17:51 CET 2018
<apeiros>
hm, right, I guess ISO will just include either TZ (using DST/non-DST distinctive names) or offset
<mkroman>
yeah.
<apeiros>
anyway, dreamy time. cya :)
<mkroman>
on the same note, Ruby is actually very good at sticking to standardized time and date formats across different libs (JSON, for example)
<mkroman>
sleep tight.
Wojnar has joined #ruby
nicesignal has quit [Remote host closed the connection]
nicesignal has joined #ruby
noark9 has quit [Quit: noark9]
kurko_ has joined #ruby
kujira has quit []
AJA4350 has quit [Quit: AJA4350]
_whitelogger has joined #ruby
kurko_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kurko_ has joined #ruby
kurko_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
asphyxia has joined #ruby
noark9 has joined #ruby
noark9 has quit [Quit: noark9]
noark9 has joined #ruby
DTZUZO has quit [Quit: WeeChat 2.0]
cpallares has joined #ruby
noark9 has quit [Quit: noark9]
johnny56 has quit [Ping timeout: 272 seconds]
dviola has joined #ruby
braincrash has quit [Quit: bye bye]
johnny56 has joined #ruby
braincrash has joined #ruby
apeiros has quit [Read error: Connection reset by peer]
apeiros has joined #ruby
im0nde has quit [Ping timeout: 252 seconds]
cow[moo] has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
nowhere_man has quit [Ping timeout: 252 seconds]
nowhereman_ has joined #ruby
im0nde has joined #ruby
apparition has joined #ruby
i8igmac has joined #ruby
nadir has quit [Quit: Connection closed for inactivity]
nezt0r has quit [Ping timeout: 252 seconds]
kapil____ has joined #ruby
noobineer has joined #ruby
<i8igmac>
can some one help me with a regex. start with a capital letter and end with a period
<i8igmac>
"Sentence one. And This one. Maybe 3."
<i8igmac>
.scan(/[A-Z].*\./)
<baweaver>
Look up regex start with and end with
nowhereman_ has quit [Read error: Connection timed out]
nowhereman_ has joined #ruby
<i8igmac>
d.scan(/\b[A-Z]\b(.*?)\b[A-Z]\b/m)
<i8igmac>
that almost does it
<i8igmac>
im close
Deesl has joined #ruby
arescorpio has joined #ruby
dviola has quit [Quit: WeeChat 2.3]
<i8igmac>
i think i found a better way.. to avoid regex
<baweaver>
split?
apparition has quit [Quit: Bye]
<i8igmac>
yah... its hard to explain how its better. with out posting a data to paste bin
<i8igmac>
im trying to put 100,000 sentences in a rails sqlite database. for use with a search bar autocomplete feature
arescorpio has quit [Quit: Leaving.]
<baweaver>
Oi, that's why you lead with things like that
<baweaver>
because the answer becomes way different
<i8igmac>
lol im skitzo or something
<i8igmac>
i try to get small snips to work, one step at a time
<i8igmac>
the help i look for is typically simple stuff. you guys make it look easy...
<i8igmac>
everything i do is automating tasks. now im working on front end stuff to create a sleek looking useful interface
<baweaver>
What's the real problem you're trying to solve?
<baweaver>
because it sounds a whole lot like full text search
apeiros__ has quit [Read error: Connection reset by peer]
apeiros has joined #ruby
tdy3 has joined #ruby
<phaul>
Inv1s1ble: can you access that url via curl / wget / web browser?
foxxx0 has quit [Quit: foxxx0]
<phaul>
I can ..
<Inv1s1ble>
huh ... it fails on the IPv6 and then drops to IPv4 ...
<Inv1s1ble>
My IPv6 routing must be screwed up
foxxx0 has joined #ruby
conta has quit [Quit: conta]
nowhereman_ has joined #ruby
patr0clus has joined #ruby
cow[moo] has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kapil____ has quit [Quit: Connection closed for inactivity]
Nicmavr has quit [Read error: Connection reset by peer]
Nicmavr has joined #ruby
dviola has quit [Quit: WeeChat 2.3]
aruns has joined #ruby
<aruns>
Hey guys, quick question, is it possible to set my environment (e.g. development, production etc.) within my Rakefile?
<aruns>
I tried set :environment, ENV['environment'] but Rakefile doesn't seem to support the set command.
<phaul>
aruns: are we talking rails here or is this rails independent discussion?
<aruns>
Rails independent.
<aruns>
I'm not a Ruby developer by trade, but have made simple webapps in Sinatra before, and have a fairly good handle on Ruby.
<aruns>
But not really done any database stuff in Ruby before.,
<phaul>
np, don't worry, someone will be able to help you here, it might not be me.. if you set an envornment variable that's exported before runing rake, on a unix system, that should be accessible via ENV['environment']
<phaul>
in bash that would be something like export environment=production
<phaul>
and the in the rakefile you should see the set value ENV['environment']
<phaul>
in other shells the syntax might differ
<aruns>
I am using Dotenv to set my env vars.
<aruns>
I should be able to load that into my Rakefile.
<phaul>
ah, I know 0 about dotenv, so I let other to take over
nowhereman_ has quit [Ping timeout: 264 seconds]
<phaul>
others*
<phaul>
and all my other spelling mistakes* :)
whysthatso has joined #ruby
<aruns>
No, Rakefiled doesn't seem to support the set command phaul
<aruns>
*Rakefile
armyriad has quit [Quit: Leaving]
<aruns>
But I have Dotenv in the Rakefile loading my .env
<aruns>
Oh, I think it's working now.
<aruns>
I just needed to load Dotenv.
<phaul>
ah. cool.
armyriad has joined #ruby
nexraf1 has joined #ruby
patr0clus has quit [Quit: WeeChat 2.1]
dellavg_ has quit [Ping timeout: 252 seconds]
agent_white has joined #ruby
patr0clus has joined #ruby
patr0clus has quit [Client Quit]
s3nd1v0g1us has joined #ruby
s3nd1v0g1us has quit [Max SendQ exceeded]
seggy has joined #ruby
seggy has quit [Remote host closed the connection]
Sembei has joined #ruby
uplime has quit [Ping timeout: 252 seconds]
nickjj has quit [Read error: Connection reset by peer]
LenPayne_ is now known as LenPayne
nickjj has joined #ruby
roshanavand has joined #ruby
<lunarkitty7>
How difficult would it be to use a bindgen to make an up to date qt5 binding?
<lunarkitty7>
Like swig
<lunarkitty7>
Similar to what they did with the crystal qt5 bindings
<lunarkitty7>
ooooh maybe just using a c only ui lib would be easier to bind
uplime has joined #ruby
nicesignal has quit [Quit: WeeChat 1.9.1]
nicesignal has joined #ruby
desperek has quit [Quit: xoxo]
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
lytol has quit [Remote host closed the connection]
reber has quit [Remote host closed the connection]
<aruns>
Hi.
<aruns>
Why am I getting NoMethodError: undefined method `migrate' for ActiveRecord::Migrator:Class?
<aruns>
I used public_instance_methods on ActiveRecord::Migrator and it lists migrate as an available method.
<aruns>
I assume it's another error altogether?
<aruns>
Does the migrate method loop through all migration files if you pass it a path?
ta_ has quit [Remote host closed the connection]
<apeiros>
?ar aruns
<ruby[bot]>
aruns: For activerecord/arel questions, please join #RubyOnRails, since they're maintained as a part of it. Note: you need to be identified with NickServ, see /msg NickServ HELP
phaul has quit [Ping timeout: 264 seconds]
bak1an has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bak1an has joined #ruby
bak1an has quit [Client Quit]
helpa has joined #ruby
warrshrike has joined #ruby
<warrshrike>
what s the difference between a lambda and an anonymous function
<warrshrike>
hey anyone there
<warrshrike>
apeiros:
<warrshrike>
long time buddy
venmx has quit [Ping timeout: 272 seconds]
<apeiros>
hi warrshrike
<warrshrike>
how are you man
<apeiros>
playing
<warrshrike>
aging well I hope? Time treating you well?
<warrshrike>
red dead 2?
<apeiros>
sc2
<warrshrike>
ah cool cool
<warrshrike>
so what IS the difference between a lambda and an anonymous function/block
<warrshrike>
is it the same thing with some doohickies added
voolik has quit [Quit: Taking a nap...]
roshanavand has quit [Ping timeout: 244 seconds]
roshanavand has joined #ruby
<warrshrike>
btw what happened to this place. there were a lot more people two years ago
<apeiros>
slack, mostly.
<lupine>
the capitalists strike again
ghormoon has quit [Excess Flood]
<warrshrike>
ah
<warrshrike>
so any idea about lambdas and blocks
ghormoon has joined #ruby
<RedNifre>
hmmm...
<RedNifre>
Is there a neater way to do BigDecimal.new("123.45") ?
<al2o3-cr>
123.45r
apeiros has quit [Read error: Connection reset by peer]
apeiros has joined #ruby
beeman has quit []
voiceftp has quit [Remote host closed the connection]
moei has quit [Quit: Leaving...]
apeiros has quit [Read error: Connection reset by peer]
<warrshrike>
if a method can be passed to another method, its first class, so to speak?
<al2o3-cr>
warrshrike: sort of.
<warrshrike>
can a method be assigned to a variable?
<al2o3-cr>
warrshrike: sure it can.
<warrshrike>
fun(:sum,a, b) sum a, b end
<warrshrike>
is this legit?
<al2o3-cr>
no.
<warrshrike>
then what is i.e. reduce gonna do with sum if it cant call it
<al2o3-cr>
hold your horses sonny jim, let's get back to the beginning. what exactly is the problem?
<warrshrike>
al2o3-cr: i was using reduce to sum chars into a string good sir
<warrshrike>
like this
<warrshrike>
a.reduce("") {|sum, num| sum + num }
<warrshrike>
so i wondered. what is happening?
<warrshrike>
in another language
<warrshrike>
most others
<warrshrike>
this is usually shorthand for
<warrshrike>
a.reduce(""), |sum, num| sum + num })
<warrshrike>
where the function is being passed as an argument which reduce will call
<warrshrike>
i.e. like forEach in javascript
<al2o3-cr>
warrshrike: as in javascript?
<warrshrike>
but apparently thats not happening here
<warrshrike>
al2o3-cr: yup
<warrshrike>
so i was wondering
<warrshrike>
what IS happening
<al2o3-cr>
i don't no javascript well, but...
<al2o3-cr>
warrshrike: i take it you understand the principle of blocks/procs?
<warrshrike>
sort of
<warrshrike>
block is just method body syntax
<al2o3-cr>
and since when could you do this in js [1,2,3].map(x => x * x)
<warrshrike>
doesnt mean much on its own
<warrshrike>
proc is an object
<al2o3-cr>
that is correct warrshrike.
<al2o3-cr>
say you have an array of [1,2,3].reduce takes a block.
<warrshrike>
al2o3-cr: let sum = arr.reduce((acc, val) => { return acc + val; });
<warrshrike>
this works in js
<warrshrike>
al2o3-cr: equivalent more or less to your js code above
<al2o3-cr>
warrshrike: this is similar to ruby
<al2o3-cr>
as in a closure.
<warrshrike>
al2o3-cr: no its taking a function object
<warrshrike>
not a block
<warrshrike>
a function in js is like any other variable
<al2o3-cr>
warrshrike: i don't know js to well :(
<warrshrike>
i.e. implementation of reduce actually calls the function provided
<warrshrike>
its similar in python, clojure etc.
<al2o3-cr>
warrshrike: well ruby is calling the block.
<warrshrike>
okay lets get back to ruby
<warrshrike>
so youre saying
<warrshrike>
reduce takes a block
<al2o3-cr>
or a method
<al2o3-cr>
but go ahead..
<warrshrike>
okay. but it doesn't 'call' the method or block inside its implementation?
<warrshrike>
can i take a block in my own custom reduce function?
<al2o3-cr>
sure, if i understand correctly.
<warrshrike>
def fun(g) g() end; g {puts "hi}
<warrshrike>
you said this isnt gonna work
<al2o3-cr>
warrshrike: try it.
<warrshrike>
def fun(g) g() end; g(:print)
<warrshrike>
tried
<warrshrike>
it wont let me pass the block to g
<al2o3-cr>
gist what you are actually doing, i might be able to come to some sense of this.
<apeiros>
warrshrike: a block is a special argument. you either invoke the block via the `yield` keyword, or by telling ruby to convert it to a Proc instance and store it in a variable by having a &block argument.
<apeiros>
def fun; yield(1); yield(15); end; fun { |value| puts "yielded #{value}" } # <-- via yield
<apeiros>
def fun(&block); block.call(1); block.call(15); end; fun { |value| puts "yielded #{value}" } # <-- via &block arg
<apeiros>
those things are ruby 101, though. as in: please read a good book :)
<warrshrike>
so a function can take only one block?
<al2o3-cr>
as apeiros shown yield is implicit and block is explicit.
<al2o3-cr>
warrshrike: a method can yes.
<apeiros>
warrshrike: correct
<warrshrike>
why did they have to overcomplicate it by dong this why not just make it first class
<al2o3-cr>
warrshrike: all methods take an implicit block.
<apeiros>
warrshrike: you can pass it any number of other arguments, though. and since you can create Proc instances via Kernel#lambda and #proc, you can pass any number of callable objects
<al2o3-cr>
"string".reverse {} # implicit block
<warrshrike>
al2o3-cr: i see. so to call that implicit block you do yield(arg) inside the function
<warrshrike>
i take it only one implicit block inside each function?
<warrshrike>
method*
<al2o3-cr>
warrshrike: yield basically yields whatever to the block; yield is the same as block.call
<warrshrike>
basically it saves having to write the argument
<al2o3-cr>
no. no.
<warrshrike>
the block argument
d10n-work has joined #ruby
<warrshrike>
what happens if no block is passed but yield(1) is there
<warrshrike>
so the main question in my mind....
<al2o3-cr>
nil
<al2o3-cr>
null
<warrshrike>
does the 'special feature' nature of blocks vs true first class functions handicap ruby in any significant way
hightower3 has joined #ruby
<al2o3-cr>
not in the slightest.
<warrshrike>
I certainly can't see any upside to doing this the way ruby does it
<warrshrike>
is there any?
<al2o3-cr>
warrshrike: in your understanding what is a block?
<hightower3>
Hey, if I have a string such as "abc://def/ghi/12345", what is the fastest way to extract the 12345? The length of this part is variable, but is guaranteed to be found after the last "/", be an integer, and be the last thing in the string.
<warrshrike>
stand alone scope of code. between { } or do end
<al2o3-cr>
warrshrike: its a closure, simple as that. that is all it is.
<warrshrike>
so its the code + env variable from the surrounding scope?
<al2o3-cr>
hightower3: s.rpartition('/')[-1]
<al2o3-cr>
probably
<warrshrike>
don't nested functions have clojures too? how would this be an advantage for block syntax
noark9 has joined #ruby
<al2o3-cr>
warrshrike: is the same if you did function foo() return function bar() end end in lua/python and god knows how many more.
<apeiros>
00:15 warrshrike: what happens if no block is passed but yield(1) is there
<al2o3-cr>
hightower3: but really it depends on the real string.
<warrshrike>
who s pry
<al2o3-cr>
or a format of the string.
<warrshrike>
pry
<al2o3-cr>
?pry warrshrike
<ruby[bot]>
warrshrike: Pry, the better IRB, provides easy object inspection `ls`, `history`, viewing docs `?`, viewing source `$`, syntax highlighting and other features (see `help` for more). Put `binding.pry` in your source code for easy debugging. Install Pry (https://pryrepl.org/): gem install pry pry-doc
<hightower3>
al2o3-cr, I tried all 3 versions... your first suggestion with rpartition takes 22 seconds for 100 mil iterations, a regex match with string =~ /\/(\d+)/ takes 28, and this last one with [/\d+/] takes 42. My last attempt will be to use rindex to find position of last "/" and then to just extract part of string from that point to end. I believe that will be the fastest
AJA4350 has quit [Quit: AJA4350]
<al2o3-cr>
hightower3: that what benchmark is for.
<al2o3-cr>
hightower3: put a \z at the end it will soon quicken up.
xfbs has quit [Quit: afk]
<hightower3>
al2o3-cr, yes I forgot to mention, the exact regex was /\/(\d+)$/... but I figured that since the string will be fixed, I can get its size up front and then do string[pos..-1]. This completes in 10 seconds
<al2o3-cr>
hightower3: sure if you know the length of the string.
<al2o3-cr>
hightower3: why does speed matter?
mikecmpbll has quit [Quit: inabit. zz.]
<hightower3>
al2o3-cr, it's part of an API, where the ID I receive is opaque and I need to read out the numeric part out
<warrshrike>
it appears you can call reduce on a string to process it char by char
<warrshrike>
is there any alternative?
<hightower3>
al2o3-cr, (it's part of server code, so I wan't to speed it up)
<hightower3>
want*
<apeiros>
warrshrike: you mean "can't"?
<apeiros>
warrshrike: string.each_char.reduce
<al2o3-cr>
hightower3: 42/1e6 or 10/1e6 will never be noticable to a human
<hightower3>
al2o3-cr, yes, but if a server is busy I better do some other stuff with those cycles
<hightower3>
anyway, there's also value in knowing the numbers now, thanks for the insights
<al2o3-cr>
well, true yes.
<al2o3-cr>
to many hertz about these days.
hightower3 has left #ruby ["Leaving"]
Wojnar has joined #ruby
<warrshrike>
def plusOne(a) ((a.reduce("") {|sum, num| sum + "#{num}" }.to_i)+1).to_s.each_char.map {|c| c.to_i} end
<al2o3-cr>
warrshrike: your thinking to much in line of js.
<warrshrike>
so this code is taking an array of numbers, adding 1 to it, and giving the result as an array of numbers after accounting for carrys etc (only single digit in each array slot
<warrshrike>
al2o3-cr: it works correctly lol
<warrshrike>
but it exceeds time limit
<warrshrike>
i was wondering what is so slow here
<warrshrike>
in asymptotic terms its just O(N)
<al2o3-cr>
this a test?
<warrshrike>
just practising
<warrshrike>
both ruby and algorithms :)
<warrshrike>
also, you mean this isnt a very 'ruby' style?
<al2o3-cr>
warrshrike: what time limit?
<warrshrike>
theres an internal execution time limit for various large inputs
<warrshrike>
its leetcode.com
<al2o3-cr>
warrshrike: can you paste the link to the problem? i'm intrigued.