[fxruby-users] drag n drop help

gga ggarra at advancedsl.com.ar
Mon Mar 5 22:06:47 EST 2007

Lyle Johnson wrote:
> On 3/5/07, Raj Sahae <rajsahae at gmail.com> wrote:
>> I want to be able to drag an object, in it's entirety.  Right now, I am
>> dragging objects by defining a to_s and card_from_str methods, but there
>> are several subclasses of these objects and writing the string
>> conversion methods is tedious for each one.  Is there another way to
>> drag an object?
> Well, there's not another way to drag an object, but that doesn't seem
> to be the problem in the first place. You're wanting to know if
> there's an easier way to specify the data that should be transferred
> whenever the user drags an object from one place to another, right?
> Have you considered using YAML to serialize (and deserialize) the
> objects? If you were to do that, it seems like you wouldn't need to
> write class-specific to_str() and from_str() methods.

Follow Lyle's advice.  YAML rocks.  Here's a quick example with two
classes (one spitting all attributes, another selectively spitting only

require 'yaml'

class A
    attr_accessor :x
    def initialize
         @x = [2,3]

a = A.new
yaml_data = YAML::dump(a)
p yaml_data

b = YAML::load(yaml_data)
p b

class B
    attr_accessor :x, :y
    def initialize
         @x = 'spit'
         @y = 'ignored'

    def to_yaml_properties
      [ '@x' ]

c = B.new
p YAML::dump(c)

Gonzalo Garramuño
ggarra at advancedsl.com.ar

AMD4400 - ASUS48N-E
Kubuntu Edgy

More information about the fxruby-users mailing list