Professional Web Applications Themes

Creating classes with from YAML? - Ruby

Remembering that all classes are instances of the Class class, is this possible? I want to create some class named, say C1, which is empty (or perhaps with one or two class instance vars) by loading a YAML doent. I can't seem to create instances of Class class in YAML, while I can easily do this in irb: $ irb irb(main):001:0> C1=Class.new => C1 irb(main):002:0> C1.new => #<C1:0x40174a1c> -- dave...

  1. #1

    Default Creating classes with from YAML?

    Remembering that all classes are instances of the Class class, is this
    possible? I want to create some class named, say C1, which is empty (or
    perhaps with one or two class instance vars) by loading a YAML doent.
    I can't seem to create instances of Class class in YAML, while I can
    easily do this in irb:

    $ irb
    irb(main):001:0> C1=Class.new
    => C1
    irb(main):002:0> C1.new
    => #<C1:0x40174a1c>

    --
    dave



    David Garamond Guest

  2. #2

    Default Re: Creating classes with from YAML?


    --3V7upXqbjpZ4EhLz
    Content-Type: text/plain; cht=us-ascii
    Content-Disposition: inline
    Content-Transfer-Encoding: quoted-printable

    David Garamond (listszara.6.isreserved.com) wrote:
    > Remembering that all classes are instances of the Class class, is this=20
    > possible? I want to create some class named, say C1, which is empty (or=
    =20
    > perhaps with one or two class instance vars) by loading a YAML doent.=
    =20
    > I can't seem to create instances of Class class in YAML, while I can=20
    > easily do this in irb:
    irb(main):002:0> 5.to_yaml
    =3D> "--- 5"
    irb(main):003:0> Class.to_yaml
    ArgumentError: can't dump anonymous class Class
    from /usr/local/lib/ruby/1.8/yaml/rubytypes.rb:8:in `to_yaml'
    from (irb):3
    irb(main):004:0> class Foo; end
    =3D> nil
    irb(main):005:0> Foo.to_yaml
    ArgumentError: can't dump anonymous class Class
    from /usr/local/lib/ruby/1.8/yaml/rubytypes.rb:8:in `to_yaml'
    from (irb):5

    Does not appear possible to do with Yaml, but you can with Marshal:

    irb(main):007:0> Marshal.dump(Foo)
    =3D> "\004\010c\010Foo"


    --=20
    Eric Hodel - [email]drbrainsegment7.net[/email] - [url]http://segment7.net[/url]
    All messages signed with fingerprint:
    FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


    --3V7upXqbjpZ4EhLz
    Content-Type: application/pgp-signature
    Content-Disposition: inline

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.2 (FreeBSD)

    iD8DBQE/cJrDMypVHHlsnwQRAkvJAJ9N6nrkRwQF1ezrs7ZDliS7YBHt9g CgzVLx
    DWyJ7VxG/eqRXHg/yvhmMhM=
    =swIg
    -----END PGP SIGNATURE-----

    --3V7upXqbjpZ4EhLz--

    Eric Hodel Guest

  3. #3

    Default Re: Creating classes with from YAML?

    C1 = YAML.load("--- !ruby/object:Class {}")


    The easiest way to figure out how to represent something in Ruby in
    YAML is just to call #to_yaml on your object:

    require 'yaml'
    C1 = Class.new
    puts C1.to_yaml #=> --- !ruby/object:Class {}

    -rich

    On Tuesday, September 23, 2003, at 03:01 PM, David Garamond wrote:
    > Remembering that all classes are instances of the Class class, is this
    > possible? I want to create some class named, say C1, which is empty
    > (or perhaps with one or two class instance vars) by loading a YAML
    > doent. I can't seem to create instances of Class class in YAML,
    > while I can easily do this in irb:
    >
    > $ irb
    > irb(main):001:0> C1=Class.new
    > => C1
    > irb(main):002:0> C1.new
    > => #<C1:0x40174a1c>
    >
    > --
    > dave
    >
    >
    >
    >

    Richard Kilmer Guest

  4. #4

    Default Re: Creating classes with from YAML?

    My bad...I was using an older version of YAML...in 1.8 this does not
    work :-(

    -rich

    On Tuesday, September 23, 2003, at 03:13 PM, Richard Kilmer wrote:
    > --- !ruby/object:Class {}

    Richard Kilmer Guest

Similar Threads

  1. Creating custom classes
    By Pea in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: March 4th, 07:14 AM
  2. yaml sequence
    By Ara.T.Howard in forum Ruby
    Replies: 0
    Last Post: October 9th, 10:59 PM
  3. YAML Patch
    By Chad Fowler in forum Ruby
    Replies: 1
    Last Post: September 9th, 02:31 AM
  4. Creating a custom control (ascx) with 'child' classes
    By Lenny in forum ASP.NET Building Controls
    Replies: 1
    Last Post: September 4th, 12:35 AM
  5. $SAFE with YAML
    By Recheis Meinrad in forum Ruby
    Replies: 0
    Last Post: August 12th, 04:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139