Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Ruby programming code please help


    :do, :do_not.include?(:try)=>false

    I saw this code on the Internet, not sure how to make this code do anything
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    83
    Rep Power
    39
    No one is going to be able to help you with that without any context.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Context?


    Originally Posted by sepp2k1
    No one is going to be able to help you with that without any context.
    Can you give me an example of context? What is context?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    83
    Rep Power
    39
    Context.

    Like where and under which circumstances you saw the code. What the code surrounding it looked like. What libraries were used etc. Or even just what the rest of that line looked like (because if you're trying to tell me that the code snippet was the whole line, I'll have to call you a liar).
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    This is where I saw the code


    This is where I saw the code.

    http://www.zazzle.com/do_do_not_include_try_false_tshirt-235744385151125668
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    83
    Rep Power
    39
    Ah, that makes a lot more sense.

    :do and :do_not are symbols. Symbols are basically immutable, interned strings, i.e. strings that can't be changed and that can be compared for equality very efficiently.

    [:do, :do_not] is an array that contains the symbols :do and :do_not.

    include? is a method of the Array class. It returns true if the given argument is an element of the array and false otherwise.

    => false isn't actually part of the code. It's a notation used to signify that the result of the above expression is false.

    So what that shirt is telling you is that the array [:do, :do_not] does not contain the symbol :try.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Question


    Originally Posted by sepp2k1
    Ah, that makes a lot more sense.

    :do and :do_not are symbols. Symbols are basically immutable, interned strings, i.e. strings that can't be changed and that can be compared for equality very efficiently.

    [:do, :do_not] is an array that contains the symbols :do and :do_not.

    include? is a method of the Array class. It returns true if the given argument is an element of the array and false otherwise.

    => false isn't actually part of the code. It's a notation used to signify that the result of the above expression is false.

    So what that shirt is telling you is that the array [:do, :do_not] does not contain the symbol :try.
    [:do, :do_not].include?(:try)=>false

    so, how do I make a terminal with that code, say, try = false
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    83
    Rep Power
    39
    What do you mean by "make a terminal with that code"? And what do you mean by "try = false"?
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Question can't get the code to anything, please help


    Originally Posted by sepp2k1
    What do you mean by "make a terminal with that code"? And what do you mean by "try = false"?
    I got this ruby programming code to work, but it doesn't do anything.

    options = {}
    options[:do] = true
    options[:do_not] = true
    options[:try] = false
    (:try)
    require 'set'
    s = Set.new ['1.1.1.1', '1.2.3.4']
    # => #<Set: {"1.1.1.1", "1.2.3.4"}>
    s.include? '1.1.1.1'
    # => true

    I just want the code to have try = false appear in a terminal, not sure how to do this though.
  18. #10
  19. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    Originally Posted by jbeannie05
    I got this ruby programming code to work, but it doesn't do anything.

    options = {}
    options[:do] = true
    options[:do_not] = true
    options[:try] = false
    (:try)
    It does just as much (or little) as the code below. If you type in the code in the IRB terminal, the last line evaluates to

    => :try

    Because (:try) is just a Symbol wrapped in parantheses (which don't do anything in this case).

    If you want to get the value for the :try key in the options hash, you have to actually write that down:

    options[:try]

    This evaluates to false.

    Note, however, that this code is completely different from the example you posted first. Instead of checking the occurence of a certain value, you retrieve a value from a hash (which happens to be a boolean).

    If you want to search for a value in a hash, you have to write something like this:

    Code:
    numbers = {
      :x => 10,
      :y => 20,
      :z => 30
    }
    numbers.has_value? 10  # evaluates to true
    numbers.has_value? 99  # evaluates to false
    By the way, in Ruby you can write down the whole hash. You don't have to put the values into the hash one by one (like in Java or so).
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    83
    Rep Power
    39
    Originally Posted by jbeannie05
    I just want the code to have try = false appear in a terminal, not sure how to do this though.
    If you're executing a ruby script (as opposed to evaluating ruby code into IRB) and you want it to print something to the terminal, you'll have to have some calls to a printing method (like puts) in your script.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Question


    this is what I wanted the code to do

    what do this code do?

    options = {}
    options[:do] = true
    options[:do_not] = true
    options[:try] = false
    (:try)
    require ‘set’
    s = Set.new [‘1.1.1.1’, ‘1.2.3.4’]
    s.include? ‘1.1.1.1’
    # this is advance ruby programming code it based on a quote by
    # yoda, yoda says something like, do or do not, there is no try
    # and this programming code in the terminal should say
    # try = false, because as yoda says, there is no try
    # so, try = false
    puts ‘try = false’
  24. #13
  25. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    So have you solved the problem yourself?

    Sorry, but I have no idea what you're trying to do. Is this just some funny code for a t-shirt? Or do you actually want to know how arrays and hashes work?
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Question arrays, hashes, t-shirt


    Originally Posted by Jacques1
    So have you solved the problem yourself?

    Sorry, but I have no idea what you're trying to do. Is this just some funny code for a t-shirt? Or do you actually want to know how arrays and hashes work?
    yeah, i want to learn ruby programming arrays and hashes, and I do want to put ruby programming code on a t-shirt.
  28. #15
  29. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,552
    Rep Power
    2337
    It's Yoda..."Do or do not; there is no try"
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo