Joel Pearson wrote in post #1103948:
If you "p" (inspect) a string, then you'll get quotes because that's how
they're represented.
If you use Jesus' method, you can add whatever you want around the
string.
Bear in mind though, that the representation of Fixnum 1 is 1, and
String 1 is "1". If you manually add quotes you might end up
misrepresenting the type of object you're using.
Thank you. The problem is not solved. The above example does not work
when i implement it to the real code . Here is the actual code. I am
trying to find usb details using dbus (ruby-dbus gem).
#!/usr/bin/env ruby
require 'rubygems'
require 'dbus'
bus = DBus::SystemBus.instance
udisk_service = bus.service("org.freedesktop.UDisks")
udisk_udisk = udisk_service.object("/org/freedesktop/UDisks")
udisk_udisk.introspect
udisk_udisk.default_iface = "org.freedesktop.UDisks"
disk_list = [udisk_udisk.EnumerateDevices]
disk_list.each { |disk|
#puts %Q{"#{disk}"}
puts disk
udisk_udisk = udisk_service.object("#{disk}")
udisk_udisk.introspect
udisk_udisk_i = udisk_udisk["org.freedesktop.UDisks.Device"]
puts udisk_udisk_i["IdUuid"]
}
disk_list is array of available disks attached to system. When i use
"put disk" in the loop i list all the disk with out problem. Like this
/org/freedesktop/UDisks/devices/sr0
/org/freedesktop/UDisks/devices/sdc
/org/freedesktop/UDisks/devices/sdb
/org/freedesktop/UDisks/devices/sda
/org/freedesktop/UDisks/devices/sda1
/org/freedesktop/UDisks/devices/sda2
/org/freedesktop/UDisks/devices/sda3
/org/freedesktop/UDisks/devices/sdc1
/org/freedesktop/UDisks/devices/sda5
/org/freedesktop/UDisks/devices/sda6
/org/freedesktop/UDisks/devices/sdb1
/org/freedesktop/UDisks/devices/sda7
/org/freedesktop/UDisks/devices/sda8
But when i quote with either "puts %Q{"#{disk}"}" or "p disk.to_s" then
the output becomes
"/org/freedesktop/UDisks/devices/sr0/org/freedesktop/UDisks/devices/sdc/org/freedesktop/UDisks/devices/sdb/org/freedesktop/UDisks/devices/sda/org/freedesktop/UDisks/devices/sda1/org/freedesktop/UDisks/devices/sda2/org/freedesktop/UDisks/devices/sda3/org/freedesktop/UDisks/devices/sdc1/org/freedesktop/UDisks/devices/sda5/org/freedesktop/UDisks/devices/sda6/org/freedesktop/UDisks/devices/sdb1/org/freedesktop/UDisks/devices/sda7/org/freedesktop/UDisks/devices/sda8"
What i want is that to list available disk with quote like this
"/org/freedesktop/UDisks/devices/sr0"
"/org/freedesktop/UDisks/devices/sdc"
"/org/freedesktop/UDisks/devices/sdb"
.
.
.
"/org/freedesktop/UDisks/devices/sda8"
so that the line "udisk_udisk = udisk_service.object("#{disk}")" takes
disk one by one.
When i provide disk_list data manually with
["/org/freedesktop/UDisks/devices/sr0",
"/org/freedesktop/UDisks/devices/sdc","/org/freedesktop/UDisks/devices/sdb",
..., "/org/freedesktop/UDisks/devices/sda8"]
and execute looping then it works.
Any help is appriciated.
···
--
Posted via http://www.ruby-forum.com/\.