sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    DATA in Ruby 1.8 working?

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 118 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      http://shifteleven.com/articles/2009/02/09/useless-ruby-tricks-data-and-end

      <span class="syntaxdefault">puts&nbsp;DATA</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read<br /><br />__END__<br /><br />Hello&nbsp;World<br /><br />Lorem&nbsp;Ipsum&nbsp;Dolor&nbsp;Sit&nbsp;Amet</span>
      

      I'm just getting NameError: uninitialized constant DATA whenever I try to use DATA - whether in SketchUp Ruby or IRB.

      Anyone got it working?

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Line 969 of Ruby.c - it's there in Ruby 1.8. So what am I doing wrong?

        <span class="syntaxdefault"><br />rb_compile_file</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">fname</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> f</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> line_start</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">if </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">script </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> ruby__end__seen</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">  rb_define_global_const</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"DATA"</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> f</span><span class="syntaxkeyword">);<br />}<br /></span><span class="syntaxdefault">else if </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">f </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> rb_stdin</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">  rb_io_close</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">f</span><span class="syntaxkeyword">);<br />}<br /><br /></span><span class="syntaxdefault">if </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">ruby_parser_stack_on_heap</span><span class="syntaxkeyword">())</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">  rb_gc</span><span class="syntaxkeyword">();<br />}<br /></span><span class="syntaxdefault"> </span>
        

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          meh!

          Seem to be that DATA isn't per file...

          http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/16387
          http://www.ruby-forum.com/topic/209628

          Workaround:
          data = File.read(__FILE__) =~ /^__END__\n/ && $' || ''

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            So assuming you want some data encapsulated within the script file itself, that will use it.

            A Here Doc, or Array or Hash, would seem to be a much easier solution.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement