require each time new

M

manveru

hi to all,

i=C2=B4m trying to build a irc-bot in ruby, and i=C2=B4ve no problem with=
that so far.
but i=C2=B4m trying to minimize the need for a restart, and want to requi=
re=20
some external code at runtime.
i know there is require "external.rb", but this seems to work only once,=20
if i require a script twice while running the program and change it=20
meanwhile, it doesn=C2=B4t seem to use the changed code, and also i don=C2=
=B4t=20
know how i get rid of the last required code.

that=C2=B4s yet another typical noob-question, i beg your pardon :)
btw, in case you didn=C2=B4t really understood what i need - the same thi=
ng=20
works in php with include("somescript.php") and that=C2=B4s exactly how i=
=20
want it to become.

thx in advance
Michael Fellinger
 
G

Greg Millam

Use load() instead of require

To get rid of old code, you might want to do something like I do.

inside a particular 'module':

class Foo < ScriptModule
def initialize() ...
register_command("foo") { |args| ... }
end
def cleanup
unregister_command("foo")
end
end

When I load() a script module, I attach all its class to its filename.
When I want to reload said filename, I first call cleanup, causing it to
unregister old code, etc, and then load() it again.

- Greg
 
B

Brian Schröder

hi to all,
=20
i=B4m trying to build a irc-bot in ruby, and i=B4ve no problem with that = so far.
but i=B4m trying to minimize the need for a restart, and want to require
some external code at runtime.
i know there is require "external.rb", but this seems to work only once,
if i require a script twice while running the program and change it
meanwhile, it doesn=B4t seem to use the changed code, and also i don=B4t
know how i get rid of the last required code.
=20
that=B4s yet another typical noob-question, i beg your pardon :)
btw, in case you didn=B4t really understood what i need - the same thing
works in php with include("somescript.php") and that=B4s exactly how i
want it to become.
=20
thx in advance
Michael Fellinger
=20
=20

Use load instead of require. Load needs the path to the file, but will
reload everytime, require is built to load everything only once.

regards,

Brian

--=20
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/
 
D

dave

--nextPart1969430.JOVY6BUgIB
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline


If you have the possibility, can you relase an Irc::Bot lib?

It would be wonderfull.



=2D-=20
here are more things in heaven and earth,
horatio, than are dreamt of in your philosophy.

--nextPart1969430.JOVY6BUgIB
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iQIVAwUAQu7wr6Ng16HTgg0AAQKxXA//S886qo81SadkLSDF4FYA3npDz/UpRkpQ
cVm9I8IWP+SYp54FffavqkwNpiKYfNCyGVnzVPycqSAnCeiRvQnuFvV0jge5lVTx
bGclWb/uQ5devxfO1IPFVx/TlRlDmH6FQ3DD/ysc00HvAjU/1fNgDsU9GDtRp2Td
CkV3ufnT2Msa7+gngtHpkvijSSdSaRslafUziTBj+0fWqTgYYfXwCf7sqZ5XmOz1
Jt2Nm+w+y63cE0mBovkVACAmGKy/+gg5YzGYB5bfDPSwiZIy3HPCNFG5uCCg4xoL
EMLqj1LcIKkwNCIQiRBOR1ipxrQQD7u5ZfiPFUe10HcjvjYj2D6U0HEe+yKYW3ZB
+DSeXLxHHsFys5CfYaAC7gfZLi/oORcWWKhICFK+uR/WHpqBMVfIkJf4qzNx+0Hg
lebiHK8Gd5QQCmPkpyeW24AMydTpTDPUNX6sTZ3RuEKdbFZeiZVkZWmViFHTSeJ1
6noR3SMrdrgLYNURUqtUGW9sHEcJ23/qJTCJtf8SeT9DhdDq4R2AWZRTECllvSg/
hfDHLsM3THhX6xm/iCFgrVYf7UDCSMANXOow0JlP2taxzyRZgEJfddzmyaQvjynp
dBonP6ta9+BMrbjcRvZuS16wVdhxJVGtzkmOisjUZX/4S5fTrbYEtGOTzskdL0+c
ZFUDnNllla8=
=4RI/
-----END PGP SIGNATURE-----

--nextPart1969430.JOVY6BUgIB--
 
M

manveru

dave said:
If you have the possibility, can you relase an Irc::Bot lib?

It would be wonderfull.
Tanks to the two who helped me with load(). it=C2=B4s working fine, and i=
can=20
code a lot faster now: ;)
but i stumbled over another problem:
i have got the hostmask of a person and i made a class User with the=20
method nick.
now i wonder, how do i create a object to represent a User?
is there a way to create a object out of a hostmask? because somewhere i=20
read that a string is no object... is that true?

this is my Userclass so far... (i know there are ways to improve that,=20
but i=C2=B4m with ruby since 3 days only :)

class User
attr_accessor :hostmask
attr_reader :nick
def initialize
@hostmask =3D ""
@nick =3D ""
end
def nick(hostmask =3D @hostmask)
if hostmask !=3D ""
@nick =3D hostmask.split("!")
@nick =3D @nick[0].split(":")
@nick[1].chomp
end
end
end


@dave
so far i don=C2=B4t know if i get to that point, as i=C2=B4m making a ver=
y=20
specialized kind of bot to control some channels.
but if you let me know what that bot should be able to do, i=C2=B4ll try =
to=20
implement it and put it online
btw: wouldn=C2=B4t it be cool to have a GPL-bot who distributes his code =
by=20
DCC? :)

so far it=C2=B4s able to respond to the most common things like PING or=20
VERSION, so it will survive in IRC, now =C3=AD=C2=B4m coding some user an=
d=20
channel-objects for manipulation.


thx in advance
Michael Fellinger
 
D

dave

--nextPart1607033.j6ng1nv9N3
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline


wouldn=C2=B4t it be cool to have a GPL-bot who distributes his code by=20
DCC? Yes.


specialized kind of bot to control some channels

module Irc
class Bot
# An "abstract" bot could be initalized with a settings obj.
# The setting obj may contain the bot name, version, and channels
# to control.
def initialize(settings)
end

def connect_to_server(server)
end

def connect_to_servers(server_ary)
end

def connect_to_server_list()
end

def disconnect()
end

# Join channels to control
def join_channels(server)
end

# Define a trigger =20
def define_trigger(trigger)
end
=20
# Activate the trigger
def activate_trigger(trigger_name)
end
end
end


I thinck this should be a good starting point for a base class.



=2D-=20
here are more things in heaven and earth,
horatio, than are dreamt of in your philosophy.

--nextPart1607033.j6ng1nv9N3
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iQIVAwUAQu8+BaNg16HTgg0AAQLTag//Z7Jsdga1Bhv0i2GVuvp6B2K+DY7VwOQQ
M4e+kDJDZ6cmhNIZluGA+ou6XVeSkRDPwu6ZwKkTBtaKBT1NAE92MFXEaM2H7cRk
ClrSbymbi7VYNu1iHhDpA/9J/8Jmbj2v7UNRntSmO6GubcWsB/YlC/hh47QIVkoc
gPpTp4YLJYBUGCSxinu4kgBO2n3IR8NCZYG2gK/umVBpRyrcfG+G+mXTIYvOq30c
j60TRfbmi/n3ReZstrrOAQH3YdXIaZst4ExarUyo0RUC/FUNQAahvHeNPQ+uCp3T
0hZvFQ8zUtWfGf7cVfVAXuGLQ4b2HLyOIee4OYmXBIdN4Gn7FEJE7CDXv4dWWKhP
DTXYmBkYHoKmjy49Dv7fHMUvO0mC+2ym25hnaETOv+qkKA33A7WjsxYxeyEHcu/Q
A+uWqmrn8iNKWLGMHROBc0gzg6H48dEFCnR7YZ0usuvYxcbfadPSWAIhDpafA/1q
jRqg7ZY2ab9fR0w8YljYEaCHwuluKQ1VcqCoQw308WO8ixU3aZ0324epdkPIZPdd
8AtAsADzWn+Qwv4vhqAhuBmLkAJgzPOoFAfmXFb4ym7FbX3eBPiD2GSt6WnVKA91
psMsPxsiWq/G+Z5sVpr3bfcYgAmVNn6w55H6M5PWx2QCRAIEjK0lAgIVC0ozsxML
VxqfSGqf7pg=
=ewRN
-----END PGP SIGNATURE-----

--nextPart1607033.j6ng1nv9N3--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,500
Latest member
ArianneJsb

Latest Threads

Top