jhass changed the topic of #ruby to: Rules & more: https://ruby-community.com | Ruby 2.5.3, 2.4.5, 2.3.8, 2.6.0-preview2: 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!
dinfuehr has quit [Ping timeout: 245 seconds]
dinfuehr has joined #ruby
xfbs has quit [Quit: afk]
fcserr has joined #ruby
kurko_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kurko_ has joined #ruby
<RedNifre> Never mind, typo...
houhoulis has joined #ruby
<apeiros> :: is for namespaces, . for methods.
<apeiros> you *can* use :: for methods, but seriously, don't.
asphyxia has joined #ruby
<mkroman> +1 apeiros
Wojnar has quit [Remote host closed the connection]
noark9 has joined #ruby
<RedNifre> thanks, but it was a typo, I was using :: in all the right places except one where I was using . so everything works as expected now...
<mkroman> however, Ruby's standard library is exceptionally bad at helping you understand methods, modules and types..
<mkroman> i.e. URI('http://example.com') is a “helper” method that is equivalent to URI.parse('http://example.com') which is *exactly* the same as URI::parse('http://example.com')
<mkroman> if you require 'uri'
<mkroman> but it's really a module.
RedNifre has quit [Ping timeout: 252 seconds]
nexraf1 has quit [Ping timeout: 252 seconds]
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?
<mkroman> wait, module_function in Kernel?
<apeiros> `Kernel.URI("http://example.com")` certainly works here.
<mkroman> oh god, another style battle?
<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
<baweaver> In which case a quick google will give you a lot better solutions
noobineer has quit [Ping timeout: 264 seconds]
<baweaver> Always lead with the problem you're trying to solve, it helps us help you better.
<i8igmac> i would have to find a demo page to see if it might work for my situation
<i8igmac> i still have to orginize the data and seed it.
meinside has quit [Quit: Connection closed for inactivity]
<i8igmac> i have already a basic working search bar with predictive text. but i didnt use a db.
Deesl has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<i8igmac> im doing it all directly from 1000 files.
<i8igmac> im working in creating a seed. with a proper schema... (another place i lack db stuff)
<i8igmac> i think i have a working snippet.
<i8igmac> at least the loop or block.
<i8igmac> when i run rake db:seed i can see the 100,000 sentences scroll across the screen
<i8igmac> this stuff is fun ;-)
<i8igmac> i need to place each sentence in the db with the page number it exist on
<i8igmac> ['page 199', ['sentence 1.', 'and more', 'still more']]
<i8igmac> ill show what i got so far
<i8igmac> its just a start... its missing the db_create[stuff]
<ruby[bot]> i8igmac: as I told you already, please use https://gist.github.com
<baweaver> Telling you, look into full text search
<i8igmac> ill check it.
<i8igmac> do you know of a demo page
nezt0r has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
evdubs_ has joined #ruby
evdubs has quit [Ping timeout: 252 seconds]
i8igmac has quit [Quit: Leaving]
apeiros has quit [Read error: Connection reset by peer]
apeiros has joined #ruby
OrangeManBad has quit [Ping timeout: 260 seconds]
apeiros has quit [Read error: Connection reset by peer]
apeiros has joined #ruby
rippa has joined #ruby
OrangeManBad has joined #ruby
phaul has joined #ruby
reber has joined #ruby
reber has quit [Remote host closed the connection]
reber has joined #ruby
OrangeManBad has quit [Ping timeout: 264 seconds]
doubledup has joined #ruby
doubledup has quit [Max SendQ exceeded]
doubledup has joined #ruby
OrangeManBad has joined #ruby
mangold has joined #ruby
dellavg_ has joined #ruby
mangold has quit [Quit: This computer has gone to sleep]
mangold has joined #ruby
seggy has joined #ruby
mangold has quit [Quit: This computer has gone to sleep]
MoritaShinobu has joined #ruby
Sembei has joined #ruby
Pisuke has quit [Ping timeout: 252 seconds]
mikecmpbll has joined #ruby
jyaworski has quit [Ping timeout: 244 seconds]
stooj_ has joined #ruby
guardian has quit [Ping timeout: 244 seconds]
drbrain has quit [Ping timeout: 244 seconds]
stooj has quit [Ping timeout: 244 seconds]
salasrod has quit [Ping timeout: 244 seconds]
salasrod_ has joined #ruby
camilasan has quit [Remote host closed the connection]
MuffinPimp_ has joined #ruby
drbrain has joined #ruby
salasrod_ is now known as salasrod
MuffinPimp has quit [Ping timeout: 244 seconds]
baweaver has quit [Ping timeout: 244 seconds]
varesa has quit [Ping timeout: 244 seconds]
balo has quit [Ping timeout: 244 seconds]
MuffinPimp_ is now known as MuffinPimp
armyriad has quit [Ping timeout: 244 seconds]
gh0sh- has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
armyriad has joined #ruby
camilasan has joined #ruby
conta has joined #ruby
Hobbyboy has quit [Quit: I think the BNC broke.]
Hobbyboy has joined #ruby
segy has quit [Excess Flood]
baweaver has joined #ruby
jyaworski has joined #ruby
petemoore has quit [Ping timeout: 252 seconds]
segy has joined #ruby
petemoore has joined #ruby
varesa has joined #ruby
Xeago has quit [Read error: Connection reset by peer]
Xeago has joined #ruby
leitz has joined #ruby
doubledup has quit [Remote host closed the connection]
xall has joined #ruby
nadir has joined #ruby
xall has quit [Client Quit]
clemens3_ has joined #ruby
TheBloke has quit [Read error: Connection reset by peer]
uplime has quit [Ping timeout: 252 seconds]
TheBloke has joined #ruby
kapil____ has quit [Quit: Connection closed for inactivity]
conta has quit [Remote host closed the connection]
clemens3_ has quit [Ping timeout: 252 seconds]
leitz has quit [Quit: Leaving]
d^sh has quit [Ping timeout: 252 seconds]
d^sh has joined #ruby
phaul has quit [Quit: bye]
apparition has joined #ruby
balo has joined #ruby
desperek has joined #ruby
conta has joined #ruby
conta has quit [Client Quit]
doubledup has joined #ruby
doubledup has quit [Remote host closed the connection]
ujjain has joined #ruby
cd has quit [Quit: cd]
RedNifre has joined #ruby
apeiros has quit [Read error: Connection reset by peer]
apeiros__ has joined #ruby
al2o3-cr has quit [Read error: Connection reset by peer]
xfbs has joined #ruby
apeiros__ has quit [Read error: Connection reset by peer]
apeiros has joined #ruby
al2o3-cr has joined #ruby
AJA4350 has joined #ruby
conta has joined #ruby
conta has quit [Remote host closed the connection]
noark9 has joined #ruby
asphyxia has quit [Ping timeout: 240 seconds]
n13z has quit [Ping timeout: 245 seconds]
n13z has joined #ruby
Tristan-Speccy has joined #ruby
aufi has joined #ruby
apeiros has quit [Remote host closed the connection]
za1b1tsu has joined #ruby
jottr has joined #ruby
guardian has joined #ruby
apeiros has joined #ruby
asphyxia has joined #ruby
apeiros__ has joined #ruby
apeiros has quit [Ping timeout: 245 seconds]
apeiros__ has quit [Remote host closed the connection]
djellemah has quit [Ping timeout: 246 seconds]
Wojnar has quit [Remote host closed the connection]
jottr has quit [Ping timeout: 246 seconds]
clemens3_ has joined #ruby
asphyxia has quit [Ping timeout: 246 seconds]
d^sh has quit [Ping timeout: 272 seconds]
d^sh has joined #ruby
thebetrayer has joined #ruby
matthewd has quit [Ping timeout: 250 seconds]
matthewd has joined #ruby
thebetrayer has quit [Ping timeout: 250 seconds]
roshanavand has joined #ruby
bmurt has joined #ruby
kapil____ has joined #ruby
apparition has quit [Quit: Bye]
za1b1tsu has quit [Ping timeout: 250 seconds]
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Dimik has joined #ruby
Dimik has quit [Excess Flood]
bmurt has joined #ruby
Dimik has joined #ruby
Dimik has quit [Excess Flood]
Dimik has joined #ruby
Dimik has quit [Excess Flood]
Dimik has joined #ruby
Dimik has quit [Excess Flood]
aufi has quit [Ping timeout: 252 seconds]
kurko_ has joined #ruby
tdy3 has quit [Ping timeout: 246 seconds]
houhoulis has joined #ruby
pabs has joined #ruby
GodFather has quit [Ping timeout: 246 seconds]
tdy3 has joined #ruby
noark9 has quit [Quit: noark9]
mangold has joined #ruby
noark9 has joined #ruby
jottr has joined #ruby
kurko_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kurko_ has joined #ruby
jottr has quit [Ping timeout: 240 seconds]
Dimik has joined #ruby
desperek has quit [Ping timeout: 244 seconds]
mangold has quit [Quit: This computer has gone to sleep]
mangold has joined #ruby
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
nowhereman_ has quit [Ping timeout: 250 seconds]
orbyt_ has joined #ruby
whysthatso has joined #ruby
beefjoe has joined #ruby
uplime has joined #ruby
tdy3 has quit [Ping timeout: 252 seconds]
whysthatso has quit [Ping timeout: 276 seconds]
ta_ has joined #ruby
doubledup has joined #ruby
doubledup has quit [Remote host closed the connection]
mangold has quit [Quit: This computer has gone to sleep]
paraxial has joined #ruby
roshanavand has quit [Ping timeout: 246 seconds]
nowhereman_ has joined #ruby
MoritaShinobu has quit [Quit: Leaving]
tdy3 has joined #ruby
jottr has joined #ruby
fcserr has quit [Ping timeout: 240 seconds]
beefjoe has quit [Quit: <3]
jottr has quit [Ping timeout: 246 seconds]
bmurt has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
beefjoe has joined #ruby
roshanavand has joined #ruby
dviola has joined #ruby
bak1an has joined #ruby
conta has joined #ruby
beefjoe has quit [Quit: <3]
cow[moo] has joined #ruby
jottr has joined #ruby
bak1an has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
seggy has quit [Remote host closed the connection]
nowhereman_ has quit [Ping timeout: 264 seconds]
jottr has quit [Quit: WeeChat 2.2]
ua has quit [Read error: Connection reset by peer]
apeiros has joined #ruby
tdy3 has quit [Ping timeout: 250 seconds]
desperek has joined #ruby
ua has joined #ruby
beefjoe has joined #ruby
Sembei has quit [Ping timeout: 245 seconds]
orbyt_ has joined #ruby
noark9 has quit [Quit: noark9]
roshanavand has quit [Quit: leaving]
dviola has quit [Ping timeout: 246 seconds]
apeiros has quit [Remote host closed the connection]
beefjoe has quit [Quit: <3]
kurko_ has quit [Quit: Textual IRC Client: www.textualapp.com]
voolik has joined #ruby
apeiros has joined #ruby
phaul has joined #ruby
dviola has joined #ruby
beefjoe has joined #ruby
beefjoe has quit [Client Quit]
nezt0r is now known as GoBleu
tdy3 has joined #ruby
patr0clus has joined #ruby
GoBleu has quit [Ping timeout: 252 seconds]
patr0clus has quit [Client Quit]
venmx has joined #ruby
apeiros has quit [Read error: Connection reset by peer]
apeiros has joined #ruby
bak1an has joined #ruby
beefjoe has joined #ruby
bak1an has quit [Ping timeout: 246 seconds]
beefjoe has quit [Client Quit]
apeiros has quit [Read error: Connection reset by peer]
apeiros__ has joined #ruby
jackrandom has joined #ruby
tdy3 has quit [Ping timeout: 246 seconds]
houhoulis has quit [Remote host closed the connection]
Eiam has quit [Ping timeout: 264 seconds]
bak1an has joined #ruby
Inv1s1ble has joined #ruby
<Inv1s1ble> I keep getting the following error if I try to add nokogiri to my Gemfile and run bundle install: Network error while fetching https://rubygems.org/quick/Marshal.4.8/nokogiri-1.8.5.gemspec.rz (execution
<Inv1s1ble> expired)
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]
<al2o3-cr> BigDecimal.new("123.45", 1e9) == 123.45r => true
apeiros has joined #ruby
asphyxia has joined #ruby
beeman has joined #ruby
leitz has joined #ruby
voiceftp has joined #ruby
helpa has quit [Remote host closed the connection]
helpa has joined #ruby
RedNifre has quit [Ping timeout: 250 seconds]
RedNifre has joined #ruby
helpa has quit [Remote host closed the connection]
helpa has joined #ruby
helpa has quit [Remote host closed the connection]
whysthatso has quit [Quit: whysthatso]
<warrshrike> a.reduce("") {|sum, num| sum + num }
<warrshrike> is this being passed as a function or block
<al2o3-cr> warrshrike: a block.
venmx has joined #ruby
<warrshrike> al2o3-cr: how does a function accept a block? Is this some magic going on
<warrshrike> i mean if the block were a function named sum
<warrshrike> could i do a.reduce "", sum
<al2o3-cr> on the other hand [1,2,3].reduce(:lcm) calls the method.
<warrshrike> or no? because there arent any higher order functions?
<warrshrike> a.reduce("", {|sum, num| sum + num }) this wont work either?
<warrshrike> al2o3-cr: method or function?
<al2o3-cr> warrshrike: baweaver has got an absolue beuty for this =)
<warrshrike> what if lcm is a free standing function
<al2o3-cr> warrshrike: method, there are no function only methods.
<warrshrike> okay so you can pass methods to other methods?
<warrshrike> using :meth syntax?
<al2o3-cr> warrshrike: for the example [1,2,3].reduce :lcm == 1.lcm(2).lcm(3) ... and so forth.
<warrshrike> al2o3-cr: yeah i mean i know how reduce works
<warrshrike> what im saying is
<warrshrike> does this mean ruby has first class methods?
<al2o3-cr> warrshrike: there is no such thing.
<warrshrike> i keep reading that ruby 'has no first class functions, but procs can be used'
<al2o3-cr> warrshrike: where are you reading this?
<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
<apeiros> try it
<apeiros> pry is your friend
<al2o3-cr> hightower3: "abc://def/ghi/12345"[/\d+/]
<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.
* al2o3-cr gnome is p***ing me off.
bak1an has joined #ruby
<warrshrike> I solved it the usual way with an array and by manually accounting for carrys
<warrshrike> I was just curious to do it in one line with ruby :P
<warrshrike> alas, it seems this way is too slow
<warrshrike> al2o3-cr: also, gnome sucks
s2013 has joined #ruby
ansraliant has joined #ruby
noark9 has quit [Quit: noark9]