Ask a Question related to Ruby, Design and Development.
-
T. Onoma #1
macros
has anyone given any thought to having macros in ruby?
perhaps there's another way to do what i want, but i'm not sure. i keep reusing the same snippit of code over and over in this one class that includes a few variables, a dumbed-down example:
"/Path/To/#{variable}/Directory"
with such a simple example one would think i only needed to set an @variable to it and resuse that, but this class is usually marshalled via yaml and hence loaded using YAML::load, so initialize will not be run. the upshot of this is that i have no single place in the class that's definitely going to be excecuted where i can set the variable. so what do you do without repeating the same snippet over and over?
oh, of course i could write a method to do it and call that each time. but this snippet really should be in a configuration file of some sort. from the example above, b/c the exact path could change.
hmmm...guess there's always eval.
thoughts?
-t0
T. Onoma Guest
-
Macros in Illustrator?
Is it possible to record a text box in a macro and/or action? I read through the action help file, but had a hard time understanding it. I want to... -
macros in Photoshop?
I have a Mavica camera that stores photos on floppies. I have to resize each photo to place them on one 8 x 10 sheet. Is there any way to memorize... -
[PHP-DEV] userland macros
Is possible to implement userland macros in a PHP extension or it can only be implemented in the core? I know that macros is a preprocessor task... -
macros in perl
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi all, I'm new to perl. How it's possible to write macros in perl? C-like macros would be... -
Finder macros in OSX
On Sat, 12 Jul 2003 14:26:04 +1000, heron stone wrote (in message <heronstone-9F4049.21260411072003@news-central.giganews.com>): Presumably... -
Dmitry V. Sabanin #2
Re: macros
11/11/2003, "T. Onoma" <transami@runbox.com> you wrote:snipped>has anyone given any thought to having macros in ruby?
>
>perhaps there's another way to do what i want, but i'm not sure. i keep reusing the same snippit of code over and over in this one class that includes a few variables, a dumbed-down example:
>
> "/Path/To/#{variable}/Directory"
>Is ("/Path/To/%s/Directory" % [variable]) usable to you?>hmmm...guess there's always eval.
>
>thoughts?
You can store string itself in some place, and then just do
(str % [variable])
--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Dmitry V. Sabanin Guest
-
Dan Doel #3
Re: macros
T. Onoma wrote:
As for this question, people have talked about macros in the past.>has anyone given any thought to having macros in ruby?
>
>
As I recall, Matz is against adding macros to Ruby because they
essentially allow people to make their
own syntax, and he'd like all Ruby to be readable by anyone who knows Ruby.
I also recall an issue with really powerful macros being a lot more
complex in Algol style languages than
they are in Lisp style languages.
In other words, you're probably out of luck as far as macros go in Ruby,
unless there's some non-standard
extention I don't know about (quite possible). You might look at
ruby-talk.org to see what's gone on in the
past with the macro discussions.
- Dan
Dan Doel Guest
-
John W. Long #4
Re: macros
T. Onoma wrote:
Ruby isn't a compiled language so you wouldn't gain a whole lot with some>
>has anyone given any thought to having macros in ruby?
>
sort of macro language in addition to what ruby already offers. You have
eval and instance_eval in Ruby, both of which accept strings as parameters
so you essentially have the ability to create your own macros:
def add_foo_method(o, name, result)
o.instance_eval %{
def #{name}
#{result}
end
}
end
o = Object.new
add_foo_method(o, :coolness_level, 10)
o.coolness_level #=> 10
def new_class(name, code)
eval %{
class #{name}
#{code}
end
}
end
new_class "A", %{
def hi
puts "hello world!"
end
}
a = A.new
a.hi #=> "hello world!"
You can abuse this technique, but it has it's place.
___________________
John Long
[url]www.wiseheartdesign.com[/url]
John W. Long Guest
-
T. Onoma #5
Re: macros
limited, but would work in one case. thanks!> Is ("/Path/To/%s/Directory" % [variable]) usable to you?
> You can store string itself in some place, and then just do
> (str % [variable])
-t0
T. Onoma Guest
-
Josef 'Jupp' SCHUGT #6
Re: macros
Hi!
* T. Onoma; 2003-11-11, 13:12 UTC:You can (ab)use the C preprocessor in the following manner:> perhaps there's another way to do what i want, but i'm not sure. i
> keep reusing the same snippit of code over and over in this one
> class that includes a few variables, a dumbed-down example:
>
> "/Path/To/#{variable}/Directory"
$ cat trick_rb.c
#define sniplet(a) ("/Path/To/" + a + "/Directory")
puts sniplet('some')
$ gcc -E trick_rb.c > trick.rb
$ cat trick.rb
# 1 "trick_rb.c"
puts ("/Path/To/" + 'some' + "/Directory")
$ ruby trick.rb
/Path/To/some/Directory
Josef 'Jupp' Schugt
--
.-------.
message > 100 kB? / | |
sender = spammer? / | R.I.P.|
text = spam? / ___| |___
Josef 'Jupp' SCHUGT Guest
-
Tim Hunter #7
Re: macros
On Wed, 12 Nov 2003 03:58:43 +0900, Josef 'Jupp' SCHUGT wrote:
If you're going to go _that_ route, why not use M4?>
> You can (ab)use the C preprocessor in the following manner:
>
> $ cat trick_rb.c
>
> #define sniplet(a) ("/Path/To/" + a + "/Directory")
> puts sniplet('some')
>
> $ gcc -E trick_rb.c > trick.rb
> $ cat trick.rb
> # 1 "trick_rb.c"
>
> puts ("/Path/To/" + 'some' + "/Directory")
>
> $ ruby trick.rb
>
> /Path/To/some/Directory
>
Tim Hunter Guest
-
Josef 'Jupp' Schugt #8
Re: macros
* Tim Hunter; Tue, 11 Nov 2003 23:00:39 GMT
I don't know if M4 is available for all platforms that are supported> On Wed, 12 Nov 2003 03:58:43 +0900, Josef 'Jupp' SCHUGT wrote:
> If you're going to go _that_ route [and use the C preprocessor],
> why not use M4?
by Ruby but I know for sure that a C compiler is available for all
platforms that Ruby runs on.
Josef 'Jupp' Schugt
Josef 'Jupp' Schugt Guest
-
Mauricio Fernández #9
Re: macros
On Mon, Nov 17, 2003 at 10:27:53AM +0900, Josef 'Jupp' Schugt wrote:
it could have been cross-compiled ;-)> * Tim Hunter; Tue, 11 Nov 2003 23:00:39 GMT
>>> > On Wed, 12 Nov 2003 03:58:43 +0900, Josef 'Jupp' SCHUGT wrote:
> > If you're going to go _that_ route [and use the C preprocessor],
> > why not use M4?
> I don't know if M4 is available for all platforms that are supported
> by Ruby but I know for sure that a C compiler is available for all
> platforms that Ruby runs on.
--
_ _
| |__ __ _| |_ ___ _ __ ___ __ _ _ __
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
Microsoft is not the answer.
Microsoft is the question.
NO (or Linux) is the answer.
-- Taken from a .signature from someone from the UK, source unknown
Mauricio Fernández Guest
-
Josef 'Jupp' SCHUGT #10
Re: macros
Hi!
* Mauricio Fernández; 2003-11-17, 21:48 UTC:[Jupp, sitting at his computer]> On Mon, Nov 17, 2003 at 10:27:53AM +0900, Josef 'Jupp' Schugt wrote:>> > * Tim Hunter; Tue, 11 Nov 2003 23:00:39 GMT
> > I don't know if M4 is available for all platforms that are supported
> > by Ruby but I know for sure that a C compiler is available for all
> > platforms that Ruby runs on.
> it could have been cross-compiled ;-)
Jupp: Ruby has been compiled so there must be a C compiler.
[Jupp types above statement]
Jupp: Waitamoment, Ruby could have been cross-compiled...
[Jupp utters humming sounds]
Jupp: No, the statement is correct. Not because there *must* be a
compiler but because there actually *is* a compiler.
Do know of a platform that for which Ruby is available but for that
no C compiler exists (native C compilers for DOS definitely exist, I
use Pacific C - cute program by the way).
Josef 'Jupp' Schugt
--
.-------.
message > 100 kB? / | |
sender = spammer? / | R.I.P.|
text = spam? / ___| |___
Josef 'Jupp' SCHUGT Guest
-
Mauricio Fernández #11
Re: macros
On Tue, Nov 18, 2003 at 09:04:47AM +0900, Josef 'Jupp' SCHUGT wrote:
If there might be no compiler, you cannot know *for sure* ;)> Hi!
>
> * Mauricio Fernández; 2003-11-17, 21:48 UTC:>> > On Mon, Nov 17, 2003 at 10:27:53AM +0900, Josef 'Jupp' Schugt wrote:> >> > > * Tim Hunter; Tue, 11 Nov 2003 23:00:39 GMT
> > > I don't know if M4 is available for all platforms that are supported
> > > by Ruby but I know for sure that a C compiler is available for all
> > > platforms that Ruby runs on.
> > it could have been cross-compiled ;-)
> Jupp: No, the statement is correct. Not because there *must* be a
> compiler but because there actually *is* a compiler.
Don't know any --- but I haven't been exposed to many different> Do know of a platform that for which Ruby is available but for that
> no C compiler exists (native C compilers for DOS definitely exist, I
> use Pacific C - cute program by the way).
platforms... such a beast might exist, somewhere.
--
_ _
| |__ __ _| |_ ___ _ __ ___ __ _ _ __
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
Microsoft is not the answer.
Microsoft is the question.
NO (or Linux) is the answer.
-- Taken from a .signature from someone from the UK, source unknown
Mauricio Fernández Guest
-
Michael Neumann #12
Re: macros
On Wed, Nov 19, 2003 at 03:32:45AM +0900, Mauricio Fernández wrote:
DJGPP is another DOS compiler (to be fair, DOS+DPMI). I've seen Ruby> On Tue, Nov 18, 2003 at 09:04:47AM +0900, Josef 'Jupp' SCHUGT wrote:
> If there might be no compiler, you cannot know *for sure* ;)
>> > Do know of a platform that for which Ruby is available but for that
> > no C compiler exists (native C compilers for DOS definitely exist, I
> > use Pacific C - cute program by the way).
compiled with it, years ago :-)
Regards,
Michael
Michael Neumann Guest
-
WATANABE Hirofumi #13
Re: macros
Hi,
Michael Neumann <mneumann@ntecs.de> writes:
Even now, the djgpp version exists:> DJGPP is another DOS compiler (to be fair, DOS+DPMI). I've seen Ruby
> compiled with it, years ago :-)
[url]http://ftp.ruby-lang.org/pub/ruby/binaries/djgpp/1.8/[/url]
--
eban
WATANABE Hirofumi Guest



Reply With Quote

