jphase has quit [Remote host closed the connection]
jphase has joined #ruby
Cohedrin_ has quit [Read error: Connection reset by peer]
zachk has quit [Quit: Leaving]
Cohedrin_ has joined #ruby
milardovich has quit [Remote host closed the connection]
jphase has quit [Ping timeout: 258 seconds]
milardovich has joined #ruby
bruno- has quit [Ping timeout: 248 seconds]
Cohedri__ has joined #ruby
AnoHito has quit [Quit: Leaving]
marr has quit [Ping timeout: 248 seconds]
Cohedrin_ has quit [Ping timeout: 258 seconds]
milardovich has quit [Ping timeout: 258 seconds]
<RickHull>
ycyclist: just curious, are you wedded to flexmock? it looks unmaintained (RIP Jim)
<ycyclist>
Yes, I know. I am somewhat wedded, but the problem is known at large. Thank you.
<ycyclist>
Interestingly, I got the case to work, but what I am stuck on now is a more general problem.
<RickHull>
what's the problem?
<ycyclist>
I need to re-initialize the require step that is presently happening at the top of the file, inside each of several flexmock blocks where I am stubbing Socket.gethostname I can set a different value.
<ycyclist>
By the way, just a second and I'll post the code I got to work:
<ycyclist>
Sorry for the dump, but:
<ycyclist>
flexmock(Socket,:strict,Socket => :gethostname, :gethostname => "myhostname") do hostname = Socket.gethostname assert_equal("myhostname", hostname, "Could not get the hostname")
<RickHull>
hm, right off the bat, it is a smell that require would have "significant" side effects
<ycyclist>
Then do your other stuff of course.
<RickHull>
require should just load code
AndBobsYourUncle has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Cohedri__ has quit [Read error: Connection reset by peer]
GodFather has quit [Ping timeout: 240 seconds]
<ycyclist>
But as you can see, what I really need is to require the stuff all over again so that the stub gets used.
<ycyclist>
I think a second require sees the first and says "naa"
CPngN has quit [Quit: The system is going down for reboot NOW!]
<RickHull>
yes, require returns true the first time
<RickHull>
and returns false the second, very quickly
<ycyclist>
There must be a way, especially for things like testing, to force a re-require.
<RickHull>
there is, but I am pretty sure you are barking up the wrong tree
<ycyclist>
We require the class to the test script and then go through all the methods and test them. We often can get away with testin things without mocks, but this one would be really helpful.
<ycyclist>
It's a Singleton.
<ycyclist>
Which makes it a little wierder.
<RickHull>
singletons are antipatterns, generally
<ycyclist>
We do Thingy.method1
<ycyclist>
Yes, well I cannot redesign the system. I can only help make it less bad.
<RickHull>
understood :)
<ycyclist>
But I agree.
<RickHull>
so, are there any effects at requiretime besides loading classes/modules and their contained methods?
<RickHull>
are any methods called or other code executed?
<ycyclist>
This is a fairly simple test. Is Ruby seriously averse to reloading inside a block and ignoring what was there before?
<ycyclist>
I have done a lot of ruby, but not that.
nankyokusei has joined #ruby
<RickHull>
ycyclist: I strongly recommend looking up what `load` does
<RickHull>
er, not looking up
<ycyclist>
There are internal methods, but these are all Class methods, no instance available except to the extent that a Class is an object anyway.
<RickHull>
even with a singleton, there is a good way and a bad way to proceed
<RickHull>
ycyclist: where does Thingy.method1 happen?
<ycyclist>
Well, I am after constructive criticism, and appreciate any you have.
Cohedrin_ has quit [Read error: Connection reset by peer]
<RickHull>
i personally guarantee any criticism from me will be 100% constructive :)
<ycyclist>
Thingy.method1 calls Socket.gethostname. It is defined inside MOD::Thingy. Pretty simple class really.
mniip has quit [Ping timeout: 600 seconds]
<RickHull>
who calls Thingy.method1 ?
<ycyclist>
Oh, it's a general utility, called all over the framework.
<RickHull>
for example, I could define Thingy and method1, and then after the module/class definition, I could call it
<RickHull>
in the same file
<RickHull>
i.e. executable code at the toplevel
<RickHull>
it will be executed at requiretime. or a constant assignment can call methods
<RickHull>
that will be executed at requiretime
nankyok__ has quit [Ping timeout: 258 seconds]
<RickHull>
I am interested, what happens at requiretime?
<RickHull>
why would you be tempted to require a 2nd time?
<ycyclist>
Yes, I want to require many times, in many different tests. Many is probably 2, but it is at least 2.
<RickHull>
why? for what effect?
<ycyclist>
Sometimes we get ip addresses back from Socket.gethostname. We want to handle that well.
Cohedrin_ has joined #ruby
<RickHull>
argh, I am not making myself clear
<RickHull>
if you do require 'blahblah', what state is changing in your program?
<RickHull>
if I do require 'yaml', then I expect the YAML module to be available
<RickHull>
I expect code declarations to be made, but no imperative code will be executed for "setup"
<ycyclist>
The state that changes is I want the stubbed Socket.gethostname to be in effect when I re-load so that Thingy.method1, which uses it, will use the stub instead of the original.
<RickHull>
ah, this is somewhat clearer
<ycyclist>
Right now, we stub Socket.gethostname, but because the stubbing happens after the definition of Thingy.method1, method1 just uses the original defintion of Socket.gethostname.
tcopeland has joined #ruby
<ycyclist>
Seems like this is a typical case for stubbing, except for the stinker of the fact that it's a Singleton and a class, not an instance object.
<ycyclist>
But I got that part kindof fixed, except, I cannot pass an instance to the thing, I need to have it defined when the module definition occurs.
<ycyclist>
All sorts of externalities could be moralized on here, but we're all human, and I like humans, so I'm working with it.
<RickHull>
you can play with Kernel.load but it's a huge terrible smell
<ycyclist>
Ok. That will be my starting point tomorrow. I fear right now my wife wants me to go home.
<ycyclist>
BTW, thank you, this is very helpful.
<RickHull>
it's like require except it happily reloads and requires the actual filename
<RickHull>
it will throw a bunch of warnings for constant redefinitions
<ycyclist>
yes, and I may find there are immutables buried in there. We'll see.
<RickHull>
calling Socket stuff directly inside a singleton is a recipe for a testing headache
bronson has joined #ruby
<ycyclist>
I will try to get back to you tomorrow about my results.
<RickHull>
I have written tons of tests but nothing successfully with mocks or stubs; testability informs my program design
<ycyclist>
Yes, but they're humans. Nice, decent-minded humans as near as I can tell.
enterprisey has joined #ruby
troys is now known as troys_
<ycyclist>
Yes. I have always tried to avoid them if possible, but sometimes stubbing and mocking are good answers.
<RickHull>
for sure, I wish I had better guidance here but I've avoided these problems somehow; I love your attitude though :)
<ycyclist>
I'm already breaking down Thingy's insides to check on its pieces, so I have it pretty well covered, but we want this too, and we will probably use it for future exigencies.
<ycyclist>
I suspect it's a good idea. I am really looking forward to migrating to minitest though. It is so much nicer.
<RickHull>
<3 minitest
<RickHull>
here is my best guess for your situation:
<ycyclist>
He, gotta go man. I will post results as soon as I squeeze'm out.
<ycyclist>
O...
<RickHull>
1. i think to mock successfully, you have to mock before require
<RickHull>
2. therefore, you may need to split out stuff that needs to be mocked (calls to Socket, etc)
<ycyclist>
Still here.
coderphive has quit [Quit: coderphive]
<ycyclist>
Yes, that is parallel to my guesses too.
<RickHull>
i.e. stop requiring at the top
bronson has quit [Ping timeout: 240 seconds]
<RickHull>
you may not need to split out your lib/source stuff
<RickHull>
but in the test script, just do your mocks first, then your requires
<RickHull>
however, there are some situations where you need to require some stuff before the mocks
<RickHull>
and thats where you may need to consider splitting out the lib/source functionality
amirite has joined #ruby
<RickHull>
i.e. split canttellyou.rb to canttellyou-core.rb and canttellyou-mocks.rb
<RickHull>
and your test script requires canttellyou-core
<RickHull>
at the top
<RickHull>
and canttellyou-mocks after the mocks
d^sh has quit [Ping timeout: 258 seconds]
d^sh has joined #ruby
paradisaeidae_ has joined #ruby
paradisaeidae has joined #ruby
<RickHull>
all that said, I am just making an educated guess. I don't know mocks and stubs very well
andikr has quit [Remote host closed the connection]
<vasilakisfil>
interesting thanks!
tcopeland has quit [Quit: tcopeland]
<vasilakisfil>
but that's inconsistend a bit. In any case, I would really like it if ruby could extend this special case to the self.foobar as well, so that we can access private accessor from inside our class seamlessly (in case we use a local variable of the same name)
GodFather has joined #ruby
John___ has joined #ruby
coderphive has joined #ruby
<matthewd>
Matz recommends `foobar()` for that
ts_ has joined #ruby
<matthewd>
But yeah, I agree it'd be more consistent to special-case self. entirely
rfoust has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
gnufied has joined #ruby
ts_ has quit [Read error: Connection reset by peer]
coderphive has quit [Client Quit]
<vasilakisfil>
ok
soahccc has quit [Quit: Cya]
Ropeney has quit [Ping timeout: 255 seconds]
chouhoulis has joined #ruby
ts_ has joined #ruby
ts_ has quit [Max SendQ exceeded]
motstgo has quit [Ping timeout: 248 seconds]
swills has quit [Ping timeout: 248 seconds]
anisha has joined #ruby
paranoicsan[Away is now known as paranoicsan
ts_ has joined #ruby
paranoicsan is now known as paranoicsan[Away
paranoicsan[Away is now known as paranoicsan
ts_ has quit [Read error: Connection reset by peer]
InfinityFye has joined #ruby
mson has joined #ruby
__Yiota has joined #ruby
workmad3 has joined #ruby
__Yiota has quit [Client Quit]
__Yiota has joined #ruby
dminuoso_ has joined #ruby
swills has joined #ruby
swills has joined #ruby
claudiuinberlin has joined #ruby
kapil___ has quit [Quit: Connection closed for inactivity]
bronson has joined #ruby
cagmz has joined #ruby
cagmz_ has quit [Ping timeout: 258 seconds]
cagmez__ has joined #ruby
dminuoso_ has quit [Ping timeout: 240 seconds]
claudiuinberlin has quit [Client Quit]
bronson has quit [Ping timeout: 260 seconds]
cagmz has quit [Ping timeout: 258 seconds]
claudiuinberlin has joined #ruby
ramfjord has joined #ruby
aclark has quit [Remote host closed the connection]
alex`` has quit [Ping timeout: 240 seconds]
ramfjord has quit [Ping timeout: 248 seconds]
jphase has joined #ruby
rfoust has joined #ruby
ledestin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rwb has quit [Ping timeout: 240 seconds]
hs366 has quit [Quit: Leaving]
mr_foto has quit [Remote host closed the connection]
Vivekananda has quit [Ping timeout: 248 seconds]
alnet has joined #ruby
headius has joined #ruby
DLSteve has joined #ruby
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
mim1k has quit [Ping timeout: 248 seconds]
bmurt has joined #ruby
jottr has joined #ruby
ramfjord has joined #ruby
__Yiota has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ramfjord has quit [Ping timeout: 255 seconds]
mr_foto has joined #ruby
emulator4 has quit [Ping timeout: 258 seconds]
mim1k has joined #ruby
Burgestrand has quit [Quit: Closing time!]
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
__Yiota has joined #ruby
jottr has quit [Ping timeout: 240 seconds]
jrafanie has joined #ruby
shinnya has quit [Ping timeout: 260 seconds]
yeticry has quit [Read error: Connection reset by peer]
yeticry has joined #ruby
jottr has joined #ruby
simmaniac has joined #ruby
ShalokShalom_ has quit [Quit: No Ping reply in 180 seconds.]
mr_foto has quit []
bmurt has joined #ruby
ShalokShalom has joined #ruby
snickers has quit [Ping timeout: 246 seconds]
sysvalve has quit [Ping timeout: 240 seconds]
__Yiota has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jrafanie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
soahccc has joined #ruby
__Yiota has joined #ruby
ta has quit [Remote host closed the connection]
Defenestrate has quit [Quit: This computer has gone to sleep]
__Yiota has quit [Client Quit]
neuraload has joined #ruby
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
charliesome has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
lagweezle_away is now known as lagweezle
marr has joined #ruby
anisha has joined #ruby
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
orbyt_ has joined #ruby
kassav_ has quit [Read error: Connection reset by peer]
kassav_ has joined #ruby
claudiuinberlin has joined #ruby
centrx has joined #ruby
centrx has quit [Changing host]
centrx has joined #ruby
pr0ton has quit [Quit: pr0ton]
pr0ton has joined #ruby
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rabajaj has quit [Remote host closed the connection]
cadillac_ has quit [Ping timeout: 248 seconds]
alfiemax has quit [Remote host closed the connection]
kassav_ has quit [Quit: kassav_]
rgr_ has quit [Quit: rgr_]
naftilos76 has joined #ruby
bruno- has quit [Ping timeout: 240 seconds]
cdg has quit [Remote host closed the connection]
oetjenj has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
cdg has joined #ruby
oetjenj has joined #ruby
<naftilos76>
hi i am trying to extract a substring from a big string with "some_string".scan(//) . Assuming that there are two words in the big string "one" and "two" and i want to extract the substring between these two words what would be your approach?
oetjenj has quit [Client Quit]
oetjenj has joined #ruby
oetjenj has quit [Client Quit]
<Papierkorb>
naftilos76: Only one occurence of a one/two pair in one big string, or possibly multiple occurences?
<naftilos76>
Papierkorb, correct question! one occurence only
gusrub has quit [Remote host closed the connection]
kies has quit [Ping timeout: 240 seconds]
<naftilos76>
Papierkorb, thanks, that would be mine but somehow it does not work
<naftilos76>
let me try a few things
pr0ton has quit [Ping timeout: 240 seconds]
ruby_ has joined #ruby
<ruby_>
I cannot require kernel. What's with that?????
<naftilos76>
Papierkorb, i have an instance that contains a big string and i do this: @file_data[/^(.*)$/, 1] and i get an empty string. Is that what it should do?
conta has quit [Ping timeout: 255 seconds]
<Papierkorb>
naftilos76: empty string or nil?
<naftilos76>
"" is what i get
<Papierkorb>
naftilos76: That regex matches an empty line
<naftilos76>
i try this while using byebug
<ruby_>
This should be simple. I cannot require kernel: require 'kernel' fails???
<Papierkorb>
ruby_: Why do you want to require that?
andikr has joined #ruby
lxsameer has quit [Quit: WeeChat 1.7]
alfiemax has joined #ruby
AndBobsYourUncle has joined #ruby
AndBobsYourUncle has quit [Client Quit]
thomasv314 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ldnunes has quit [Read error: Connection reset by peer]
<Papierkorb>
troulouliou_dev: That's a key-word argument with a default value of `true`. To pass a different value to it, you have to explicitly pass the keyword name: `valid?(foo, check_empty: false)`. You can't omit the name, this won't work: `valid?(foo, false)`
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
<troulouliou_dev>
Papierkorb, ok thanks
perniciouscaffei has joined #ruby
aclark has joined #ruby
petr_ has quit [Client Quit]
<troulouliou_dev>
Papierkorb, they are position independant i guess if i use several then
<Papierkorb>
You're correct, they are :)
<troulouliou_dev>
Papierkorb, awesome thanks
<Papierkorb>
cheers
ta has joined #ruby
mim1k has quit [Ping timeout: 240 seconds]
linetrace has joined #ruby
adlerdias has quit [Quit: adlerdias]
Rapture has joined #ruby
elitetnade has joined #ruby
jrafanie_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kt has quit [Ping timeout: 240 seconds]
dviola has joined #ruby
shinnya has joined #ruby
elitetnade has quit [Remote host closed the connection]
jrafanie has joined #ruby
mson has quit [Quit: Connection closed for inactivity]
claudiuinberlin has joined #ruby
claudiuinberlin has quit [Client Quit]
Kestrel-029 has quit [Read error: Connection reset by peer]
__Yiota has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
zachk has joined #ruby
enterprisey has quit [Remote host closed the connection]
naftilos76 has quit [Ping timeout: 260 seconds]
someuser has quit [Ping timeout: 258 seconds]
dinfuehr has quit [Ping timeout: 264 seconds]
ta has quit [Ping timeout: 258 seconds]
dinfuehr has joined #ruby
claudiuinberlin has joined #ruby
cadillac_ has quit [Read error: Connection reset by peer]
spt0 has quit [Ping timeout: 264 seconds]
gusrub has quit [Remote host closed the connection]
troulouliou_dev has quit [Quit: Leaving]
troulouliou_dev has joined #ruby
amirite has joined #ruby
cadillac_ has joined #ruby
eroux has quit [Quit: ZZZzzz… ZZZzzz…]
gusrub has joined #ruby
eckhardt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
[Butch] has quit [Quit: I'm out . . .]
linetrace has left #ruby [#ruby]
eckhardt has joined #ruby
ta has joined #ruby
jenrzzz has quit [Ping timeout: 260 seconds]
enterprisey has joined #ruby
sysvalve has quit [Quit: Leaving]
mtkd has quit [Read error: Connection reset by peer]
ta has quit [Ping timeout: 258 seconds]
mtkd has joined #ruby
amirite has quit [Ping timeout: 248 seconds]
kt has joined #ruby
eckhardt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
eckhardt has joined #ruby
Rythen has joined #ruby
lexruee has quit [Quit: ZNC 1.6.5-frankenznc - http://znc.in]
lexruee has joined #ruby
gusrub has quit [Remote host closed the connection]
elitedhort has quit [Read error: Connection reset by peer]
Alina-malina has quit [Ping timeout: 240 seconds]
Guest97372 has quit [Ping timeout: 258 seconds]
harfangk has quit [Ping timeout: 248 seconds]
milardovich has joined #ruby
Alina-malina has joined #ruby
milardovich has quit [Client Quit]
Puffball_ has quit [Remote host closed the connection]
<Rythen>
Hi I'm new to Ruby. I was wondering if it's considered better form to use symbols or strings as keys in Ruby. Is one considered more right or is it just preference that varies from developer to developer?
<matthewd>
Rythen: It really depends where the keys are coming from
bronson has joined #ruby
lagweezle_away is now known as lagweezle
<matthewd>
Rythen: If it's all in straight code, symbols are handy. If you're using externally-input data, strings are more common.
Alina-malina has quit [Ping timeout: 260 seconds]
tcopeland has quit [Quit: tcopeland]
imode has quit [Ping timeout: 246 seconds]
Alina-malina has joined #ruby
ramfjord has joined #ruby
bronson has quit [Ping timeout: 240 seconds]
<Rythen>
matthewd: So if you were for example parsing strings and ptuting them into a hash it'd be better to keep the keys as strings since that's what they originally are?
<matthewd>
Yeah
Alina-malina has quit [Ping timeout: 240 seconds]
ta has joined #ruby
gusrub has joined #ruby
Alina-malina has joined #ruby
rfoust has joined #ruby
ta has quit [Ping timeout: 255 seconds]
dionysus69 has quit [Ping timeout: 264 seconds]
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
snickers has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Kanibal>
Is there a quick solution to further "improve" this? (omit the dot?)
jenrzzz has quit [Ping timeout: 240 seconds]
jphase has quit [Ping timeout: 246 seconds]
cdg_ has joined #ruby
jenrzzz has joined #ruby
jenrzzz has quit [Changing host]
jenrzzz has joined #ruby
kanobt61 has quit [Remote host closed the connection]
cdg has quit [Ping timeout: 248 seconds]
kanobt61 has joined #ruby
thinkpad has joined #ruby
kanobt61 has quit [Ping timeout: 248 seconds]
Alina-malina has quit [Ping timeout: 240 seconds]
Alina-malina has joined #ruby
enterprisey_ has joined #ruby
__Yiota has joined #ruby
enterprisey has quit [Ping timeout: 260 seconds]
bruno- has quit [Ping timeout: 248 seconds]
SeepingN has quit [Quit: The system is going down for reboot NOW!]
Alina-malina has quit [Ping timeout: 248 seconds]
Alina-malina has joined #ruby
tfitts has joined #ruby
ta has joined #ruby
Heph_ has joined #ruby
Rythen has quit [Ping timeout: 260 seconds]
quobo has quit [Quit: Connection closed for inactivity]
ta has quit [Ping timeout: 240 seconds]
Heph_ has quit [Quit: Leaving]
nchambers has quit [Changing host]
nchambers has joined #ruby
nchambers has quit [Changing host]
nchambers has joined #ruby
Alina-malina has quit [Ping timeout: 260 seconds]
Alina-malina has joined #ruby
phaul has quit [Ping timeout: 240 seconds]
<cagomez_>
whats the preferred object creation pattern when you want to pass in a variable and immediately get a return value back? like a throwaway object that doesn't really need to hold any state, just generate a string (for example) based on the params
<teatime>
sounds like a function?
bruno- has joined #ruby
<cagomez_>
teatime: let's say i want to make it into a class/object
<cagomez_>
one example i saw is SomeObject.call() where SomeObject had def self.call; new.call(); end; def cell; doStuff; end; end;
jphase has joined #ruby
rwb has joined #ruby
bastilian_ has quit [Quit: bastilian_]
ta has joined #ruby
jphase has quit [Ping timeout: 258 seconds]
bastilian_ has joined #ruby
<elomatreb>
Is it necessary to create an instance internally like that?
Alina-malina has quit [Ping timeout: 240 seconds]
<elomatreb>
I.e. can't you just put the logic (doStuff) in the self.call method?