xuanrui has quit [Remote host closed the connection]
Freshnuts has quit [Quit: Leaving]
DTZUZO has quit [Ping timeout: 272 seconds]
za1b1tsu_ has joined #ruby
za1b1tsu has quit [Ping timeout: 240 seconds]
Alina-malina has quit [Ping timeout: 272 seconds]
pabs has quit [Ping timeout: 260 seconds]
sameerynho has joined #ruby
za1b1tsu has joined #ruby
za1b1tsu_ has quit [Ping timeout: 256 seconds]
nowhereman_ has joined #ruby
tristanp has joined #ruby
MarcWeber has joined #ruby
<MarcWeber>
Which library to parse date differences like '2 days' ?
tristanp has quit [Ping timeout: 272 seconds]
postmodern has quit [Quit: Leaving]
dionysus69 has joined #ruby
xuanrui has joined #ruby
xuanrui has quit [Read error: Connection reset by peer]
drbrain has quit [Ping timeout: 272 seconds]
<MarcWeber>
Which library to parse date differences like '2 days' ?
<MarcWeber>
<ArahaelPi>
MarcWeber: I saw your first question, and I still don't know.
<ArahaelPi>
MarcWeber: Someone might, but re-posting doesn't help.
kevinsjoberg has joined #ruby
wolfshappen has quit [Ping timeout: 244 seconds]
<MarcWeber>
I did repost because Irssi showed 'joined' after me having send the message, so I was uncertain whether it showed up at al.l
<MarcWeber>
I thought its a very common issue, eg PHP has a DateDiff class which gets it done perfectly. I could just wirte a 3line PHP script .. it sucks but works.
wolfshappen has joined #ruby
<ArahaelPi>
Well, do that, and if someone response, apply the improved version.
reber has quit [Remote host closed the connection]
<apeiros>
MarcWeber: not sure whether chronic also handles duration
<apeiros>
it's the only one I remember which handles natural language dates, though
<apeiros>
if the format is fixed and simple enough, you can build something on your own relatively easily, though. regex + factor lookup table
<apeiros>
that would fit your description alex``. but then again, why do I even bother, didn't even get any kind of response to when I last wrote something.
Kug3lis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kapil___ has joined #ruby
danguita has quit [Client Quit]
<havenwood>
alex``: Is that ^ what you meant when you said "merge 2 arrays (superpose) like hash)"?
<alex``>
apeiros: Awesome
<alex``>
havenwood: Yep
<alex``>
I was going with zip or to_h, but apeiros lot much clear in intent
guardian has quit [Remote host closed the connection]
<havenwood>
alex``: If you show us what info you're trying to get at, maybe we can suggest a better way to get it from the command line. When you have multiple arguments you want to pass, it can be really nice to pass them coupled by name rather than position.
<havenwood>
alex``: Arguments are of course by position. Options are by name.
danguita has quit [Client Quit]
<alex``>
havenwood: where ARGV.options is from ?
<havenwood>
alex``: It gets defined when you: require 'optionparser'
<havenwood>
alex``: Alternatively you can: OptionParser.new do ...
<nikivi>
check karabiner.rb which has many methods
<nikivi>
and config.rb where I try to call them
sarna has joined #ruby
Dbugger has quit [Ping timeout: 265 seconds]
<havenwood>
nikivi: You're trying to call them with a different receiver than `main` at top level.
<nikivi>
what does that mean?
<havenwood>
nikivi: derr
<havenwood>
nikivi: You should go ahead and just use Modules.
<havenwood>
nikivi: I meant, *err
<nikivi>
not too familiar with modules, reading it now
<nikivi>
do I have to wrap all my methods as module?
<havenwood>
nikivi: Sec, I'll gist and example
<havenwood>
nikivi: A module with module_function is a really nice way to namespace.
<nikivi>
is there no way to just require the thing and use its methods as if they are in the same file
<havenwood>
yes, you can do just that
<sarna>
hey, is "The Ruby Programming Language" still relevant? it's from 2008
<havenwood>
nikivi: that's why i'm a bit confused why your example isn't working, but this is enough code it's hard to see the minimal reproducible case
<havenwood>
sarna: That's still a good book. It's pretty easy to catchup on the last ten years if you understand that book.
<nikivi>
config.rb:14:in `main': undefined method `simkeys' for main:Object (NoMethodError)
<nikivi>
from config.rb:34:in `<main>'
<nikivi>
I get this error trying to call rb on config.rb
<nikivi>
ruby*
<havenwood>
nikivi: You define simkeys in that same file, 20 lines later.
<nikivi>
ohh
<nikivi>
I think its due to main
<nikivi>
it has to be at the bottom
<havenwood>
nikivi: It's a good example of why to use a Module and module_function.
<nikivi>
okay I think it works now
<nikivi>
I just though I could call main right after def main
<nikivi>
and still do def's after main call
<havenwood>
nikivi: You can, but you haven't defined the other methods yet.
<sarna>
havenwood: thanks
<nikivi>
yeah makes sense
<nikivi>
just in JS you can do that
<nikivi>
declare stuff at end of files and use it earlier
<havenwood>
nikivi: Use a module. Sec, I'll gist something for you.
<nikivi>
but it seems I dont need modules in this case
<nikivi>
it seems to work like I want
<havenwood>
nikivi: you don't *need* them, but it's a good idea and will save you from issues like what bit you
<havenwood>
nikivi: the modules are to make our lives better, not for the machines
<havenwood>
nikivi: no prob, any time
<alex``>
havenwood: Slop is awesome :)
dionysus69 has joined #ruby
<havenwood>
alex``: Thank ljarvis :-)
IanMalcolm has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
impermanence has quit [Remote host closed the connection]
<alex``>
I like it doesn’t have assumption upon how CLI should be
<alex``>
there is no -h --help, etc.
<alex``>
or GNU long option forced
sspreitz has quit [Ping timeout: 265 seconds]
d1rewolf has joined #ruby
<d1rewolf>
all, I'm confused. I would expect: Regexp.new('(\S*)').match("ruby is great") to return three groups (ruby, is, and great). however, it only returns one
<d1rewolf>
although testing on rubular, it seems to return three. what am I overlooking?
jdawgaz has joined #ruby
sspreitz has joined #ruby
<d1rewolf>
I'd like to split a string on a pattern, but store what matches the pattern to split as well. So, if I had "x===a".split(/=*/)
<d1rewolf>
i'd get "x", "===", and "a". is there a method which does this?
sarna has quit [Quit: Quit]
leah2 has quit [Ping timeout: 240 seconds]
<elomatreb>
d1rewolf: match only gets you the first match (if any) by design, you probably want String#scan
jdawgaz has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Nicmavr has quit [Read error: Connection reset by peer]
jdawgaz has joined #ruby
Nicmavr has joined #ruby
code_zombie has joined #ruby
DLSteve has quit [Quit: All rise, the honorable DLSteve has left the channel.]
jdawgaz has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
faitswulff has quit [Remote host closed the connection]
herbmillerjr has joined #ruby
thejs has joined #ruby
Mikel_ has joined #ruby
galeido has quit [Remote host closed the connection]
s2013 has joined #ruby
jottr has joined #ruby
jottr has quit [Ping timeout: 276 seconds]
xlegoman has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
apparition has quit [Quit: Bye]
dionysus69 has quit [Ping timeout: 276 seconds]
galeido has joined #ruby
faitswulff has joined #ruby
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #ruby
bsamorim has joined #ruby
faitswulff has quit [Remote host closed the connection]
graphene has quit [Remote host closed the connection]
<bsamorim>
Hi! I'm having trouble installing ruby from source: I followed the instructions from the ruby website. The installation itself succeded but, when I tried running `gem install bundler`, I got the error "Unable to require openssl, install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources"
graphene has joined #ruby
<bsamorim>
Is this a known issue?
xlegoman has joined #ruby
dionysus69 has joined #ruby
xlegoman has quit [Client Quit]
<bsamorim>
The only oddity about my installation is that I'm running every command as the root user.
<bsamorim>
Could this be the cause of the issue?
<bsamorim>
I have openssl installed, by the way
code_zombie has quit [Quit: Leaving]
fmcgeough has quit [Quit: fmcgeough]
darkhanb has joined #ruby
nowhereman_ has joined #ruby
theRealGent has joined #ruby
<apeiros>
bsamorim: I think ruby detects openssl, if it can't find it, it builds without. and then that kind of things happen.
<bsamorim>
apeiros: thanks a lot for the tip! Is it thinner than rvm?
<apeiros>
I think rvm uses that for building ruby (and some other version managers too I think)
<bsamorim>
ok, thanks!
IanMalcolm has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
Zaab1t has joined #ruby
tristanp has joined #ruby
tristanp has quit [Ping timeout: 256 seconds]
graphene has quit [Remote host closed the connection]
graphene has joined #ruby
riclima has quit [Ping timeout: 244 seconds]
nowhereman_ has quit [Ping timeout: 276 seconds]
IanMalcolm has joined #ruby
reber has quit [Read error: Connection reset by peer]
drbrain has joined #ruby
faitswulff has joined #ruby
faitswulff has quit [Ping timeout: 276 seconds]
s2013 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
johnny56 has quit [Read error: Connection reset by peer]
riclima has joined #ruby
s2013 has joined #ruby
nowhereman_ has joined #ruby
johnny56 has joined #ruby
sauvin has quit [Remote host closed the connection]
s2013 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
tpendragon has quit [Remote host closed the connection]
sarna has joined #ruby
Freshnuts has joined #ruby
jottr has joined #ruby
<riclima>
Hello
<apeiros>
hi riclima, welcome to #ruby
jottr has quit [Ping timeout: 276 seconds]
<riclima>
I'm a Python developer learning Ruby. I'm trying to get a grip on the Ruby development workflow
<riclima>
What's the Ruby equivalent for virtualenv?
<riclima>
And/or is it even needed?
<apeiros>
as far as I understood what virtualenv does, I'd say rvm or rbenv
<apeiros>
those are for ruby versions
<apeiros>
bundler for the libraries
<riclima>
Right
<riclima>
So from my understanding
<apeiros>
i.e. you put a .ruby-version and a Gemfile into your projects and you should be settled.
<riclima>
I use bundler to make my gems, and that's the basics?
<apeiros>
uh, you can use bundler to create a skeleton for a new gem too, yes
<apeiros>
the more common use of it is to enforce specific versions of your dependencies in your projects
<riclima>
cool, so bundler also manages dependencies?
<apeiros>
in a way. the part it does is enforcing of versions.
<apeiros>
I'm not sure how much it does and how much of the work it delegates to rubygems.
<riclima>
apeiros: alright, thanks for the help. I'll jump in on the bundler documentation and go from there.
<riclima>
Cheers
<apeiros>
if you make a gem, your Gemfile will usually be mostly empty and just reference the *.gemspec file of your gem.
<elomatreb>
One difference to Python might be that bundler and friends don't do the "environment changing" that virtualenv does, you need to prefix commands or use explicit stubs to *force* it to use your specified versions
<apeiros>
oh, I think I forget about that because rvm does it. I never prefix `bundle exec`
<apeiros>
but good point
<elomatreb>
Does it actually apply bundler constraints or is it just a side effect of isolating the installed gems?
<apeiros>
I don't use gemsets if you refer to that
* apeiros
just realized that he's oblivious about the actual mechanics of this
<elomatreb>
The fallback behavior from what I remember if you don't prefix bundle exec is to use the latest installed version of a gem
<apeiros>
I guess I should fix that one day :D
<apeiros>
no, it is run via bundler
<apeiros>
otherwise it wouldn't abort if stuff is checked out in the wrong version (git stuff in Gemfile) or not updated/installed.
<elomatreb>
In short, Rubygems: Gemfile goes in -> *magic* -> something is executed
sarna has quit [Quit: Leaving]
druonysus has joined #ruby
t0x has joined #ruby
dionysus69 has quit [Ping timeout: 272 seconds]
s2013 has joined #ruby
Zaab1t has quit [Quit: Zaab1t]
DTZUZO has joined #ruby
IanMalcolm has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
s2013 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
s2013 has joined #ruby
dellavg has quit [Ping timeout: 240 seconds]
savolla has joined #ruby
qolq3 has joined #ruby
Xiti` has joined #ruby
IanMalcolm has joined #ruby
Freshnuts has quit [Remote host closed the connection]
Freshnuts has joined #ruby
Tempesta has quit [Ping timeout: 272 seconds]
thy0 has quit [Ping timeout: 240 seconds]
qolq has quit [Ping timeout: 272 seconds]
qolq3 is now known as qolq
Xiti has quit [Ping timeout: 272 seconds]
dionysus69 has joined #ruby
nowhereman_ has quit [Ping timeout: 272 seconds]
tpendragon has joined #ruby
IanMalcolm has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
kapil___ has quit [Quit: Connection closed for inactivity]
JoshS has joined #ruby
IanMalcolm has joined #ruby
orbyt_ has joined #ruby
thy0 has joined #ruby
dviola has joined #ruby
Fr4n has quit [Remote host closed the connection]
IanMalcolm has quit [Ping timeout: 256 seconds]
IanMalcolm has joined #ruby
thejs has quit [Remote host closed the connection]
s2013 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
riclima has quit [Ping timeout: 244 seconds]
s2013 has joined #ruby
IanMalcolm has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
graphene has quit [Read error: Connection reset by peer]
graphene has joined #ruby
s2013 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
s2013 has joined #ruby
RedNifre has joined #ruby
<RedNifre>
hey there!
<apeiros>
hallo erfinder
<RedNifre>
schnell geblickt!
<apeiros>
well, I've seen you a couple of times
<RedNifre>
jedenfalls, I was wondering how to sort of do a command line stream script in ruby and how to get a result from it.
<RedNifre>
:)
<RedNifre>
Yeah, I tend to come back here... and to other channels.
jdawgaz has joined #ruby
<RedNifre>
Anyway, I thought I should try out the old unix tools sed, awk, etc. but I'm not sure it's worth it.
<apeiros>
$stdout.sync = true or $stdout.flush after you write
<RedNifre>
What I have right now is something that preprocesses a log on the fly, but I need to do some accumulation on it... i guess with ruby I would just pipe to the ruby script which would read from stdin... but since this is sorta infinite, where should I access the accumulated results?
<apeiros>
I guess that depends a lot on when you want to have access to accumulated results
<apeiros>
and in what form
jottr has joined #ruby
<apeiros>
and what other information you want to get out of that script
s2013 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<RedNifre>
Say the log looks like "Bob bought 23 green bananas for $10,00 from you." and I already trimmed it down to "Bob 23 green bananas 10.00"... I want to accumulate the money for each purchase per item...
<RedNifre>
Oh, wait, maybe I'm just thinking to complex here...
s2013 has joined #ruby
<RedNifre>
I guess I'll just print the whole state of the script on every purchase so I'll always see the latest state when I look at the terminal window.
<RedNifre>
That way, there is no "end" result.
<apeiros>
that could be a viable approach, yes. printing running totals.
jdawgaz has quit [Client Quit]
<apeiros>
I'm not sure logfiles are the right place for things like this, though.
<apeiros>
that's the domain of databases.
<RedNifre>
It's just a toy project from a game.
<RedNifre>
I thought about this, too, but a database might be overkill.
<apeiros>
eh, sqlite is easy to add.
<RedNifre>
Sure, but hear me out.
<RedNifre>
This is the situation: There is a game, in that game you can open virtual shops and you get chat messages when people buy or sell to your shop. The game logs the chat to a txt file.
<apeiros>
there's a big chance other approaches will end up with you having to do a lot more than if you just add a dependency and throw each purchase into a table. summing is trivial from there.
<RedNifre>
So my idea is to count what's in my shop when I log in, tell it to the script, and the script reads the chat log to keep the inventory tally updated.
<RedNifre>
I considered it and my plan right now is to actually do both.
<RedNifre>
however, the nature of the game makes all this very transient.
jottr has quit [Ping timeout: 244 seconds]
<RedNifre>
i.e. when i log off people will still interact with the shop, which means the inventory count will diverge
<apeiros>
you don't get offline messages?
<RedNifre>
so what really matters is the inventory count when i log in plus all following chat messages
<RedNifre>
right
<RedNifre>
it's not a serious professional system, it's just a tiny game that isn't even about shops
<RedNifre>
I want to put all the messages in a sqlitedb anyway so i can easily figure out who my most frequent customers are etc. but the immediate goal is more transient.
<RedNifre>
...but that might get a bit too far off topic now... I guess I'll try piping the sed output into a ruby script and have it process it... it's just `gets`, right? For one line of stdin?
<RedNifre>
(it's been a while since i last used ruby)
<apeiros>
yes
postmodern has joined #ruby
<RedNifre>
Thanks, I'll see what happens...
<apeiros>
Kernel#gets reads from ARGF, which without values in ARGV is just $stdin.gets.
jdawgaz has joined #ruby
<apeiros>
if you strictly want to read from stdin, you should do $stdin.gets, though. people get confused about "why does ruby say 'no such file `foobar`'?" when they invoke their script as `somescript foobar`.
graphene has quit [Read error: Connection reset by peer]
graphene has joined #ruby
dionysus69 has quit [Ping timeout: 268 seconds]
<RedNifre>
well, i tried `some sed stuff | ruby myscriptrb` and `gets` seems to return empty strings.
<apeiros>
that'd mean you got empty lines as input.
<RedNifre>
I'm not familiar with the "different" stdin... where in the ruby script do the 5000 lines that get emitted by the sed stuff appear?
<RedNifre>
To keep it simple I tried to write an echo command in ruby, just while true do line = gets; puts "got #{line}"; end, nothing too fancy.
<apeiros>
stuff piped ends up on $stdin and waits there until you read it
<apeiros>
"where in the ruby script" - wherever you read from $stdin.
<elomatreb>
Floats are often the source of bugs or weird behaviors in games, e.g. if you use them for coordinates your points become more spaced out if you go far from the center
reber has joined #ruby
<elomatreb>
It depends on the numbers
<elomatreb>
>> 0.1 + 0.1 + 0.1
<ruby[bot]>
elomatreb: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<elomatreb>
#=> 0.30000000000000004
s2013 has joined #ruby
apeiros has joined #ruby
<RedNifre>
yeah, but if i round to 2 places it's still correct
<weaksauce>
it can be
<weaksauce>
if it's just for a game without precision worries you can get away with it
<RedNifre>
okay, another thing, how do I do a hash where every entry kinda already exists with value 0.00 ? so I can just do myhash[some_previously_unknown_key] += some_amount ?
<elomatreb>
Hash.new(0.0)
<RedNifre>
ruby sure is simple :)
<elomatreb>
There is a caveat with this if you want to use it with "complicated" objects instead of the "primitives" like numbers, reading the docs of Hash#new is worthwhile
apeiros has quit [Ping timeout: 240 seconds]
s2013 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<RedNifre>
well, it seems to work... is there a simple list to turn this into an ordered high score list like [["key34", 1000.00], ["key90", 980.00]...] ?
apeiros has joined #ruby
<RedNifre>
sleepwalking?
<RedNifre>
never mind, I'll figure it out...
fmcgeough has joined #ruby
<elomatreb>
RedNifre: Enumerable#
<elomatreb>
ignore that, sorry
<elomatreb>
Enumerable#sort_by will help you and was what I meant to say
apeiros has quit [Ping timeout: 276 seconds]
<RedNifre>
well, I did hashmap.to_a.sort { |a, b| a[1] <=> b[1] } instead
<elomatreb>
Hashes are ordered and implement Enumerable, so the to_a step is not necesssary fwiw