I'm a new member

Hi evrybody!
I'm a new member of forum ruby .
I meet with serious difficulties
Can you help me?
I have project write for compare different C++ with ruby (EX: Class
String )
thanks.

···

--
Posted via http://www.ruby-forum.com/.

Que1bbb3nh Tre1baa7n wrote:

Hi evrybody!
I'm a new member of forum ruby .
I meet with serious difficulties
Can you help me?

Certainly. Please state the problem.

···

--
Paul Lutus
http://www.arachnoid.com

I don't know about C++ strings, what are they like?

···

On Dec 2, 2006, at 23:49 , Quỳnh Trần wrote:

Can you help me?
I have project write for compare different C++ with ruby (EX: Class String )

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!

Hi all,

I want to print all the methods in excel OLE object
in alphabetic order but the sort method is
unavailable. Can anyone explain it and help me fix it?

Thank you,

Li

···

##
require 'win32ole'
excel = WIN32OLE.new('Excel.Application')
m = excel.ole_methods
p m.class
p m.sort

##screen output

ruby sort1.rb

Array
sort1.rb:6:in `sort': undefined method `<=>' for
Rows:WIN32OLE_METHOD (NoMethodError)
  from sort1.rb:6

Exit code: 1

____________________________________________________________________________________
Need a quick answer? Get one in minutes from people who know.
Ask your question on www.Answers.yahoo.com

Eric Hodel wrote:

···

On Dec 2, 2006, at 23:49 , Quỳnh Trần wrote:

Can you help me?
I have project write for compare different C++ with ruby (EX: Class
String )

I don't know about C++ strings, what are they like?

That depends. If the OP is describing ordinary C++ strings (not the string
class), they are like a traditional C string, e.g. a series of characters
terminated with a zero byte. If the OP is referring to ANSI strings, this
page may help describe it:

http://www.msoe.edu/eecs/ce/courseinfo/stl/string.htm

Unfortunately the original post doesn't say clearly which "string" is meant.

--
Paul Lutus
http://www.arachnoid.com

Hi all!

Li Chen wrote:

I want to print all the methods in excel OLE object
in alphabetic order but the sort method is
unavailable. Can anyone explain it and help me fix it?

Thank you,

sorry
could you like to make yourself clear !
thanks.

···

--
Posted via http://www.ruby-forum.com/\.

chen li wrote:

Hi all,

I want to print all the methods in excel OLE object
in alphabetic order but the sort method is
unavailable. Can anyone explain it and help me fix it?

Thank you,

Li
##
require 'win32ole'
excel = WIN32OLE.new('Excel.Application')
m = excel.ole_methods
p m.class
p m.sort

##screen output

ruby sort1.rb

Array
sort1.rb:6:in `sort': undefined method `<=>' for
Rows:WIN32OLE_METHOD (NoMethodError)
from sort1.rb:6

Exit code: 1

One solution is to convert the entire OLE data array into an equivalent Ruby
type, such as an array of Ruby strings, and sort those. In this case, you
could take the "excel.ole_methods" list and insert it into a Ruby array,
hopefully as strings, and sort the resulting array.

···

--
Paul Lutus
http://www.arachnoid.com

sort_by is your friend. I don't have a windows machine handy to
experiment, but say an Rows:WIN32OLE_METHOD defines a #name, you can
say

p m.sort_by {|i| i.name}

or even

m.map {|i| i.name}.sort

if what you want is the names, rather than the Rows:WIN32OLE_METHOD
objects themselves.

Of course, if you *can* print it, it evidently defines to_s and
inspect methods, so this will work:

puts m.map {|i| i.to_s}.sort

or

puts m.map {|i| i.inspect}.sort

martin

···

On 12/3/06, chen li <chen_li3@yahoo.com> wrote:

##
require 'win32ole'
excel = WIN32OLE.new('Excel.Application')
m = excel.ole_methods
p m.class
p m.sort

Quỳnh Trần wrote:

Hi all!

Li Chen wrote:

I want to print all the methods in excel OLE object
in alphabetic order but the sort method is
unavailable. Can anyone explain it and help me fix it?

Thank you,

sorry
could you like to make yourself clear !
thanks.

That was a thread hijack. Either there's a problem with one of the
gateways that makes new threads appear as replies to old ones, or Some
People Don't Know Better (tm).

Either way, it wasn't supposed to be an answer to your problem.

David Vallner

Thanks and all of them work. But I just don't
understand why the line code below works

p m.sort_by {|i| i.name}

yet p m.sort.each{|i| i.name} FAILS.

Li

···

--- Martin DeMello <martindemello@gmail.com> wrote:

sort_by is your friend. I don't have a windows
machine handy to
experiment, but say an Rows:WIN32OLE_METHOD defines
a #name, you can
say

p m.sort_by {|i| i.name}

or even

m.map {|i| i.name}.sort

if what you want is the names, rather than the
Rows:WIN32OLE_METHOD
objects themselves.

Of course, if you *can* print it, it evidently
defines to_s and
inspect methods, so this will work:

puts m.map {|i| i.to_s}.sort

or

puts m.map {|i| i.inspect}.sort

martin

____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

Hi --

sort_by is your friend. I don't have a windows
machine handy to
experiment, but say an Rows:WIN32OLE_METHOD defines
a #name, you can
say

p m.sort_by {|i| i.name}

or even

m.map {|i| i.name}.sort

if what you want is the names, rather than the
Rows:WIN32OLE_METHOD
objects themselves.

Of course, if you *can* print it, it evidently
defines to_s and
inspect methods, so this will work:

puts m.map {|i| i.to_s}.sort

or

puts m.map {|i| i.inspect}.sort

martin

Thanks and all of them work. But I just don't
understand why the line code below works

p m.sort_by {|i| i.name}

yet p m.sort.each{|i| i.name} FAILS.

sort and sort_by work by comparing pairs of objects using the <=>
("spaceship") method. So in your second example, you're asking Ruby
to do this:

   object1 <=> object2 # etc.

The problem is (I assume) that these objects don't have a <=> method.

However, if you compare by name, you're doing:

   object1.name <=> object2.name

Since names are strings, they *do* have a <=> method, so the
comparison can take place.

You can always define <=> for your class:

   class C
     attr_accessor :name
     def <=>(other)
       self.name <=> other.name
     end
   end

There's another issue, though. Here:

   m.sort.each{|i| i.name}

I don't think you really want each. each returns its receiver, so
that snippet is functionally equivalent to:

   m.sort

If you want to grab all the names in a new array, you would use map
rather than each.

David

···

On Sun, 3 Dec 2006, chen li wrote:

--- Martin DeMello <martindemello@gmail.com> wrote:

--
                   David A. Black | dblack@wobblini.net
Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] Ruby for Rails | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

Hi all,

Thank you in advance for any feedback.

I need to print out the values for Excel constants.
But the code I use just print the constant's name. The
only way I can get the values for constants is to
print them one by one. What is the Ruby way to do it?

Li

···

##
require 'win32ole'

class Excel_Const
end

excel=WIN32OLE.new('Excel.Application')
WIN32OLE.const_load(excel, Excel_Const)

#puts Excel_Const.constants.sort
Excel_Const.constants.sort.each{|i| puts i}

puts
puts "This is the value"
puts Excel_Const::XlFullPage

##output
CONSTANTS
Xl24HourClock
...
XlYes
XlZero
This is the value
3

Exit code: 0

____________________________________________________________________________________
Any questions? Get answers on any topic at www.Answers.yahoo.com. Try it now.

Use const_get - it's a method defined on Module.

Excel_Const.constants.sort.each{|i|
  puts "The value of Excel_Const::#{i} is "+Excel_Const.const_get(i)
}

martin

···

On 12/3/06, chen li <chen_li3@yahoo.com> wrote:

I need to print out the values for Excel constants.
But the code I use just print the constant's name. The
only way I can get the values for constants is to
print them one by one. What is the Ruby way to do it?

Thank you very much. BTW it doesn't work when + is
there so I change the code into the following:

Excel_Const.constants.sort.each do|i|
print "Excel_Const::#{i} is ","\t",
Excel_Const.const_get(i)
puts
end

Li

···

--- Martin DeMello <martindemello@gmail.com> wrote:

Use const_get - it's a method defined on Module.

Excel_Const.constants.sort.each{|i|
  puts "The value of Excel_Const::#{i} is
"+Excel_Const.const_get(i)
}

____________________________________________________________________________________
Any questions? Get answers on any topic at www.Answers.yahoo.com. Try it now.

Oops - yes, + assumes that all the constants are strings. Should have
been +Excel_Const.const_get(i).to_s

You could also just inline it into the string: puts "The value of
Excel_Const::#{i} is #{Excel_Const.const_get(i)}" since #{}
automatically calls to_s on the return value of the block.

martin

···

On 12/3/06, chen li <chen_li3@yahoo.com> wrote:

--- Martin DeMello <martindemello@gmail.com> wrote:

> Use const_get - it's a method defined on Module.
>
> Excel_Const.constants.sort.each{|i|
> puts "The value of Excel_Const::#{i} is
> "+Excel_Const.const_get(i)
> }

Thank you very much. BTW it doesn't work when + is
there so I change the code into the following:

Once again thank you very much,

Li

···

--- Martin DeMello <martindemello@gmail.com> wrote:

You could also just inline it into the string:
puts "The value of
Excel_Const::#{i} is #{Excel_Const.const_get(i)}"
since #{}
automatically calls to_s on the return value of the
block.

martin

____________________________________________________________________________________
Need a quick answer? Get one in minutes from people who know.
Ask your question on www.Answers.yahoo.com