User Profile

Collapse

Profile Sidebar

Collapse
beatTheDevil
beatTheDevil
Last Activity: Sep 8 '08, 06:19 AM
Joined: Nov 17 '06
Location: Seattle
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Metaprogramming in Ruby: class_eval vs. instance_eval

    I'm using Ruby 1.8.6 btw.

    For the longest time today (it seems) I've been trying to understand exactly the operating difference between class_eval and instance_eval. There are some obvious differences I'm perfectly aware of (e.g. class_eval is only on Class objects), but the reality is that some irb tinkering has left me more confused than ever. Given the following:

    Code:
    class Foo
      # could be any class
    ...
    See more | Go to post

  • beatTheDevil
    started a topic Ruby and object references / copying
    in Ruby

    Ruby and object references / copying

    Hey guys,

    I had a theoretical question about Ruby's object handling. Not that it really matters, but I'm using Ruby 1.8.6.

    In Ruby, every variable holds a reference to an object. For instance, if you were to say:

    [code=ruby]
    myVar1 = []
    myVar2 = myVar1
    myVar2 << "giggity giggity goo"

    myVar[0] # => "giggity giggity goo"
    [/code...
    See more | Go to post
    Last edited by beatTheDevil; Sep 21 '07, 05:48 AM. Reason: ...forgot to finish a sentence

  • I apologize. I'm an idiot. I had a typo in my sample file. Misaw is right; this does, in fact work. However, you don't need the (typeof ___ == "function") . Simply conditionalizin g on undefined works just fine.
    See more | Go to post

    Leave a comment:


  • This doesn't work. The problem is that, at the time of parsing, the JavaScript interpreter can find no definition of "myLateFunction " and so this test is never even considered. Try it. Just make an HTML file out of this and see what happens...

    [CODE=html]<script type="text/javascript">
    function earlyFunction() {
    if(typeof lateFunction != 'undefined' && typeof lateFunction == 'function')...
    See more | Go to post

    Leave a comment:


  • beatTheDevil
    replied to When to use if vs else if
    The bottom line is this:

    Use if statements if you want every condition tested. Theoretically, every if-wrapped code block could be executed if its conditional expression evaluated to "true."

    Use if/else statements when you want only one of a number of possibilities to be executed under a particular set of circumstances.
    See more | Go to post

    Leave a comment:


  • So you have a Java program that you want to output trace/debugging information in JavaScript? Where is this Java program running? Is it an applet or are you running a full-fledged Java application?

    Either way you'll find that outputting to standard out (the console, in Java "System.out.pri ntln()") is not a very good way to get JavaScript interpreted.

    If you can state more clearly what it is that you are trying...
    See more | Go to post

    Leave a comment:


  • JavaScript strings are immutable : ) (they can never be changed once constructed)...
    See more | Go to post

    Leave a comment:


  • Late binding / dynamic dispatch: using a function not yet defined

    I searched, I swear. All my keywords were ignored by the search engine. Or I may just suck at searching with the right keywords, but I've been unable to find information about this. Perhaps somebody can elaborate.

    I would to like to create a function, included in the header of an HTML page, which calls functions which are defined later, in <script /> tags farther down in the body of the page (I understand this is a terrible idea,...
    See more | Go to post

  • More specifically, even though it works fine on one-line strings, I think I've found that it's unable to match this style of comments across new lines ("\n"). Is there a way to get around this? I thought the '.' matched any character whatsoever...
    See more | Go to post

    Leave a comment:


  • beatTheDevil
    replied to Nuby to Ruby (and all programming)
    in Ruby
    Have you looked at Why's Poignant Guide to Ruby? For most experienced programmers it's just frustratingly simple, but if you've truly never programmed before, it might be a better place to start than the Pickaxe. It's geared for beginners.

    The full text is freely available here:

    http://poignantguide.net/ruby/...
    See more | Go to post

    Leave a comment:


  • Ruby regex for removing C/Java-style /* ... */ comments

    Hey guys,

    As the title says I'm trying to make a regular expression (regex/regexp) for use in removing the comments from code. In this case, this particular regex is meant to match /* ... */ comments.

    I'm using Ruby v.1.8.6

    Here's my regex:
    Code:
    multiline_comments = /\/\*(.*?)\*\//
    When I try
    Code:
    myStr.gsub(multiline_comments, "")
    I see no effect. The string has big fat comments...
    See more | Go to post

  • beatTheDevil
    replied to CSS with firefox
    If you're going to be spending much time with this, there is a single tool that will make your life much much easier.

    https://addons.mozilla. org/en-US/firefox/addon/1843

    Firebug is the best Firefox add-on I've worked with (I've found it to work much better than the Web Developer Toolbar for most things). It allows you to inspect every element in your document, observe its inherited CSS styles, its computed styles, modify...
    See more | Go to post

    Leave a comment:


  • beatTheDevil
    replied to Eclipse Question Mac and PC
    in Java
    Sandy, your problem may have something to do with the fact that Apple, being somewhat stubborn and stingy with the implementation details of their operating system, doesn't allow Sun to write Java for the Mac. They write their own version and install it on their computers.

    At the moment, only Java 1.5.x is available for Mac users. It looks like you need to upgrade from 1.4.2, so go to Apple's website, not Sun's or Eclipse's, and search...
    See more | Go to post

    Leave a comment:


  • Well of course you could hack it and use a Map as Jos suggested. Simply encapsulate your multiple values into a single Object of some kind (a List, Set, Array, etc.) and store that as your value. Makes your life a bit more difficult, but you could get it to work easily enough. To be super-clear, your mappings would take the form:

    <key, List(value 1, value 2, ..., value n)>

    Making your own data structure is only...
    See more | Go to post

    Leave a comment:


  • Behavior of C++ input streams at the end of the stream

    Hello all,

    I have a question that concerns how C++ input streams (istream, ifstream, istringstream, etc.) behave using the extraction (>>) operator when at the end of a stream's contents.

    For instance, I have an input file which is just a one-line string: "do_stuff 20060101 " (yes, that is a trailing space)

    I'm using a parse function that attempts to extract a string ("do_stuff")...
    See more | Go to post

  • beatTheDevil
    started a topic Invoking a copy ctor semi-explicitly
    in C

    Invoking a copy ctor semi-explicitly

    First off, I'm not a complete idiot, so by "explicitly " I don't mean like this:

    MyClass imAnIdiot.MyCla ss(params);

    Here's what I'm getting at. If you have written a copy constructor for a class, is it legal to invoke this constructor in a "new" statement as follows?

    MyClass oldObject(param 1, param2);
    MyClass* newObject = new MyClass(oldObje ct);

    I can't imagine...
    See more | Go to post
No activity results to display
Show More
Working...