Search Results

Search found 724 results on 29 pages for 'constants'.

Page 6/29 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • ruby in 100 minutes good_morning method issue

    - by user2525947
    I have been doing the Ruby in 100 minutes on the JumpStart labs website, and encountered a problem during part 5. I was asked to create a good_morning method that would print out a greeting such as 'Happy Monday, it's the 130 day of 2013'. Here is my current program: class PersonalChef def good_morning today = Date.today.strftime("%A") day_of_year = Date.today.yday puts "Happy#{today}! It is the #{day_of_year} day of year." return self end def make_toast(color) puts " Making your toast #{color}!" return self end def make_milkshake(flavor) puts " Making a #{flavor} milkshake!" return self end def make_eggs(quantity) puts " Making you #{quantity} eggs!" return self end end when I try to run the program load on irb( 'personal_chef.rb', frank = PersonalChef.new, frank.make_milkshake('chocolate'), etc, everything works fine until I try to type frank.good_morning into irb, which gives the following error message: NameError: uninitialized constant PersonalChef :: Date from personal_chef.rb:5: in good_morning from (irb):3 from /bin/irb:12:in '' Any help or information to help me solve this issue would be greatly appreciated. Thanks for your time!

    Read the article

  • consts and other animals

    - by bks
    Hello i have a cpp code wich i'm having trouble reading. a class B is defined now, i understand the first two lines, but the rest isn't clear enough. is the line "B const * pa2 = pa1" defines a const variable of type class B? if so, what does the next line do? B a2(2); B *pa1 = new B(a2); B const * pa2 = pa1; B const * const pa3 = pa2; also, i'm having trouble figuring out the difference between these two: char const *cst = “abc”; const int ci = 15; thank you

    Read the article

  • how to use a PHP Constant that gets pulled from a database

    - by Ronedog
    Can you read out the name of a PHP constant from a database and use it inside of a php variable, to display the value of the constant for use in a menu? For example here's what I'm trying to accomplish In SQL: select menu_name AS php_CONSTANT where menu_id=1 the value returned would be L_HOME which is the name of a CONSTANT in a php config page. The php config page looks like this define('L_HOME','Home'); and gets loaded before the database call. The php usage would be $db_returned_constant which has a value of L_HOME that came from the db call, then I would place this into a string such as $string = '<ul><li>' . $db_returned_constant . '</li></ul>' and thus return a string that looks like $string = '<ul><li><a href="#" onclick="path_from_db">Home</a></li></ul>'. To sum up what I'm trying to do Load a config file based on the language preference query the db to return the menu name, which is the name of a CONSTANT in the config file loaded in step one, and also retrieve the menu_link which is used in the "onclick" event. Use a php variable to hold the name of the CONSTANT Place the variable into a string that gets echo'd out to create the menu displaying the value of the CONSTANT. I hope this makes enough sense...is it even possible to use a constant like this? Thanks.

    Read the article

  • Is there a a C-like way to get item number from enum in java ?

    - by Hernán Eche
    Perhap this is a simple basic question Having an enum public enum TK{ ID,GROUP,DATA,FAIL; } Can I get the order number for example ID=0, GROUP=2, DATA=3, FAIL=4 ? This is a way to to that, but a weird and long one! =S public enum TK{ ID(0),GROUP(1),DATA(2),FAIL(3); int num; TK(int n) { this.num=n; } public int get() { return num; } }; to get numbers so I write TK.ID.get(), TK.GROUP.get(), etc... I don't like that there is a better way? ( C enums, C macros..I miss you both ) thanks

    Read the article

  • C++: defining maximum/minimum limits for a class

    - by Luis
    Basically what the title says... I have created a class that models time slots in a variable-granularity daily schedule (where for example the first time slot is 30 minutes, but the second time slot can be 40 minutes); the first available slot starts at (a value comparable to) 1. What I want to do now is to define somehow the maximum and minimum allowable values that this class takes and I have two practical questions in order to do so: 1.- does it make sense to define absolute minimum and maximum in such a way for a custom class? Or better, does it suffice that a value always compares as lower-than any other possible value of the type, given the class's defined relational operators, to be defined the min? (and analogusly for the max) 2.- assuming the previous question has an answer modeled after "yes" (or "yes but ..."), how do I define such max/min? I know that there is std::numeric_limits<> but from what I read it is intended for "numeric types". Do I interpret that as meaning "represented as a number" or can I make a broader assumption like "represented with numbers" or "having a correspondence to integers"? After all, it would make sense to define the minimum and maximum for a date class, and maybe for a dictionary class, but numeric_limits may not be intended for those uses (I don't have much experience with it). Plus, numeric_limits has a lot of extra members and information that I don't know what to make with. If I don't use numeric_limits, what other well-known / widely-used mechanism does C++ offer to indicate the available range of values for a class?

    Read the article

  • C++: Define simple string?

    - by Jason
    This thing is really wracking my mind. I'm learning C++ and I wanted to define a constant that I can use in another function, A short answer on how to do this will be fine.. Lets say at the beginning of my code I want to define this constant: //After #includes bool OS = 1; //1 = linux if (OS) { const ??? = "clear"; } else { const ??? = "cls"; } I don't know what type to use to define the "clear" string... I'm so confused. Later on I want to use it within a function: int foo() { system(::cls); //:: for global return 0; } How would I define the string up top, and use the string down below? I heard char only had one character and things... I'm not sure how to use , since it says it's converting string into const char or something.

    Read the article

  • Why does C# not allow const and static on the same line?

    - by Cuga
    Why does C# not allow const and static on the same line? In Java, you must declare a field as 'static' and 'final' to act as a constant. Why does C# not let you declare const's as final? I make the further distinction that in Java, every interface is public and abstract, whether this is explicitly declared or not. Aren't const's effectively static in nature? WHy does C# balk at this?

    Read the article

  • how to get a constant in java with class

    - by vincent
    basically I need to get a constant for a class however I have no instance of the object but only its class. In PHP I would do constant(XYZ); Is there a similar way of retrieving a constant in JAVA? I need it to facilitate a dynamic getMethod call Class parameterType = Class.forName(class_name); object.setProperty(field name, field value, parameterType); the set property method would then get the correct method and set the specified property, however I cant get a method which has int as parameter type without using Interger.TYPE

    Read the article

  • How to define a constant when running script/server?

    - by Zeke
    I want to start up my Rails development server like this: script/server OFFLINE_MODE=1 and have a method that checks for the presence of that constant: helper_method :offline_mode? def offline_mode? defined?(OFFLINE_MODE) ? true : false end so I can hide stuff in my app when I'm coding without access to the internet. For some reason though, OFFLINE_MODE doesn't ever seem to be defined and the method always returns false.. thoughts?

    Read the article

  • Constant member

    - by TGadfly
    I have structure defined in some header (D3DXVECTOR3) How can I declare: static member in the class of that type and initialize it? maybe constant member of that type and init it? when i use some constructor i get error only integral can be initialized.

    Read the article

  • Can you use constant variables in javascript?

    - by chobo2
    Hi I am using visual studios 2010 and created a javascript file(jscript.js) and I saw on one page saying you can make constant variables in javascript like: const x = 20; bu to on another page I read it says you can't. So I am confused now what is it now? Also in Visual studios when I write "const" it underlines it in the javascript file and goes syntax error.

    Read the article

  • ActionScript Reading Static Const Array

    - by TheDarkIn1978
    how can i evaluate weather my test array is equal to my static constant DEFAULT_ARRAY? shouldn't my output be returning true? public class myClass extends Sprite { private static const DEFAULT_ARRAY:Array = new Array(1, 2, 3); public function myClass() { var test:Array = new Array(1, 2, 3); trace (test == DEFAULT_ARRAY); } //traces false

    Read the article

  • PHP: constant as variable in function

    - by m4recek
    I'm trying to use constant as a function paramter, is it possible to check type of this constant. Example of what I want: class ApiError { const INVALID_REQUEST = 200; } class Response { public function status(ApiError $status) { //function code here } } USE: $response = new Response(); $response->status(ApiError::INVALID_REQUEST); This shoud check that given $status is constant of class ApiError. Is something like this possible?

    Read the article

  • Is it relevant to warn about truncating real constants to 32 bits?

    - by zneak
    I'm toying around with LLVM and looking at what it would take to make yet another strongly-typed language, and now that I'm around the syntax, I've noticed that it seems to be a pet peeve of strongly typed language to warn people that their constants won't fit inside a float: // both in Java and C# float foo = 3.2; // error: implicitly truncating a double into a float // or something along these lines Why doesn't this work in Java and C#? I know it's easy to add the f after the 3.2, but is it really doing anything useful? Must I really be that aware that I'm using single-precision reals instead of double-precision reals? Maybe I'm just missing something (which, basically, is why I'm asking). Note that float foo = [const] is not the same thing as float foo = [double variable], where requiring the cast seems normal to me.

    Read the article

  • Smooth Camera Zoom Factor Change

    - by Siddharth
    I have game play scene in which user can zoom in and out. For which I used smooth camera in the following manner. public static final int CAMERA_WIDTH = 1024; public static final int CAMERA_HEIGHT = 600; public static final float MAXIMUM_VELOCITY_X = 400f; public static final float MAXIMUM_VELOCITY_Y = 400f; public static final float ZOOM_FACTOR_CHANGE = 1f; mSmoothCamera = new SmoothCamera(0, 0, Constants.CAMERA_WIDTH, Constants.CAMERA_HEIGHT, Constants.MAXIMUM_VELOCITY_X, Constants.MAXIMUM_VELOCITY_Y, Constants.ZOOM_FACTOR_CHANGE); mSmoothCamera.setBounds(0f, 0f, Constants.CAMERA_WIDTH, Constants.CAMERA_HEIGHT); But above thing create problem for me. When user perform zoom in and leave game play scene then other scene behaviour not look good. I already set zoom factor to 1 for this purpose. But now it show camera translation in other scene. Because scene switching time it so much small that player can easily saw translation of camera that I don't want to show. After camera reposition, everything works perfect but how to set camera its proper position. For example my loading text move from bottom to top or vice versa based on camera movement. Any more detail you want then I can able to give you.

    Read the article

  • How do I pull `static final` constants from a Java class into a Clojure namespace?

    - by Joe Holloway
    I am trying to wrap a Java library with a Clojure binding. One particular class in the Java library defines a bunch of static final constants, for example: class Foo { public static final int BAR = 0; public static final int SOME_CONSTANT = 1; ... } I had a thought that I might be able to inspect the class and pull these constants into my Clojure namespace without explicitly def-ing each one. For example, instead of explicitly wiring it up like this: (def *foo-bar* Foo/BAR) (def *foo-some-constant* Foo/SOME_CONSTANT) I'd be able to inspect the Foo class and dynamically wire up *foo-bar* and *foo-some-constant* in my Clojure namespace when the module is loaded. I see two reasons for doing this: A) Automatically pull in new constants as they are added to the Foo class. In other words, I wouldn't have to modify my Clojure wrapper in the case that the Java interface added a new constant. B) I can guarantee the constants follow a more Clojure-esque naming convention I'm not really sold on doing this, but it seems like a good question to ask to expand my knowledge of Clojure/Java interop. Thanks

    Read the article

  • How to distinguish properties from constants if they both use PascalCasing for naming?

    - by Gishu
    As stated in the framework design guidelines and the WWW in general, the current guideline is to name your constants like this LastTemplateIndex as opposed to LAST_TEMPLATE_INDEX With the PascalCasing approach, how do you differentiate between a Property and a Constant. ErrorCodes.ServerDown is fine. But what about private constants within your class ? I use quite a lot of them for naming magic numbers.. or for expected values in my unit tests and so on. The ALL_CAPS style helps me know that it is a constant . _testApp.SelectTemplate(LAST_TEMPLATE_INDEX); *Disclosure: I have been using the SCREAMING_CAPS style for a while for constants + I find it more readable than squishedTogetherPascalCasedName. It actually STANDS_OUT in a block of text*

    Read the article

  • How do I call a variable from another class?

    - by squeezemylime
    I have a class called 'Constants' that I am storing a String variable in. This class contains a few global variables used in my app. I want to be able to reference this class and call the variable (called profileId) in other Views of my app. I looked around and found a few examples, but am not sure how to do this. Currently my setup is: Constants.h @interface Constants : UIViewController { NSString *profileId; } @property (nonatomic, retain) NSString *profileId; @end Constants.m #import "Constants.h" @implementation Constants @synthesize profileId; - (void)dealloc { [profileId release]; [super dealloc]; } And I am trying to call the variable profileId in a new View via this way: NewView.h file @class Constants; NewView.m file NSLog(@"ProfileId is:", [myConstants profileId]); Is there something I'm missing? It is coming up null, even though I am properly storing a value in it in another function via this way: Constants *Constant; Constant = [[Constants alloc] init]; Constant.profileId = userId;

    Read the article

  • Java regex patterns - compile time constants or instance members?

    - by KepaniHaole
    Currently, I have a couple of singleton objects where I'm doing matching on regular expressions, and my Patterns are defined like so: class Foobar { private final Pattern firstPattern = Pattern.compile("some regex"); private final Pattern secondPattern = Pattern.compile("some other regex"); // more Patterns, etc. private Foobar() {} public static Foobar create() { /* singleton stuff */ } } But I was told by someone the other day that this is bad style, and Patterns should always be defined at the class level, and look something like this instead: class Foobar { private static final Pattern FIRST_PATTERN = Pattern.compile("some regex"); private static final Pattern SECOND_PATTERN = Pattern.compile("some other regex"); // more Patterns, etc. private Foobar() {} public static Foobar create() { /* singleton stuff */ } } The lifetime of this particular object isn't that long, and my main reason for using the first approach is because it doesn't make sense to me to hold on to the Patterns once the object gets GC'd. Any suggestions / thoughts?

    Read the article

  • Where can I define Conditional compilation constants for Delphi Prism?

    - by Martijn
    I've just ported a Web service from Delphi.NET 2006 to Delphi Prism 2009 (running in the Visual Studio 2008 IDE). But I can't find where I'm supposed to set (or unset) the conditional compilation constants! Am I blind, has this option been left out, or is it just not supported in VS? [edit: thanks to Mohammed Nasman for the link] MSDN tells me to set them using the Project Designer. First, it took me a while to figure out that the Project menu is only visible when the Solution is selected (and not the web service project). Then, there's still no way to set conditional compilation constants in the Project Designer! I just can't find a way to get to the Project Options in an ASP.NET project... Is it really not possible?

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >