Tutorial by Examples: const

User is an ActiveRecord or Mongoid class. Replace User with any Rails class in your project (even something like Integer or Array) my_string = "User" # Capitalized string # => 'User' my_constant = my_string.safe_constantize # => User my_constant.all.count # => 18 my...
This example will not work because the string passed in isn't recognized as a constant in the project. Even if you pass in "array", it won't work as it isn't capitalized. my_string = "not_a_constant" # => 'not_a_constant' my_string.safe_constantize # => nil my_s...
Cons-cells, structures, vectors, lists and such can be matched with constructor patterns. (loop for i from 1 to 30 do (format t "~5<~a~;~>" (match (cons (mod i 3) (mod i 5)) ((cons 0 0) "Fizzbuzz")...
Primary Constructor In Scala the primary constructor is the body of the class. The class name is followed by a parameter list, which are the constructor arguments. (As with any function, an empty parameter list may be omitted.) class Foo(x: Int, y: String) { val xy: String = y * x /* now...
A class constructor must have the same name as its class. Let's create a constructor for a class Person: class Person { String name; String gender; int age; Person(this.name, this.gender, this.age); } The example above is a simpler, better way of defining the constructor than the...
const int a = 0; /* This variable is "unmodifiable", the compiler should throw an error when this variable is changed */ int b = 0; /* This variable is modifiable */ b += 10; /* Changes the value of 'b' */ a += 10; /* Throws a compiler error */ The const qualif...
In Common Lisp, if is the simplest conditional construct. It has the form (if test then [else]) and is evaluated to then if test is true and else otherwise. The else part can be omitted. (if (> 3 2) "Three is bigger!" "Two is bigger!") ;;=> "Three is bigger...
A pointer to a const object can be converted to a pointer to non-const object using the const_cast keyword. Here we use const_cast to call a function that is not const-correct. It only accepts a non-const char* argument even though it never writes through the pointer: void bad_strlen(char*); const...
R has a number of build in constants. The following constants are available: LETTERS: the 26 upper-case letters of the Roman alphabet letters: the 26 lower-case letters of the Roman alphabet month.abb: the three-letter abbreviations for the English month names month.name: the English names fo...
Single Pointers Pointer to an int The pointer can point to different integers and the int's can be changed through the pointer. This sample of code assigns b to point to int b then changes b's value to 100. int b; int* p; p = &b; /* OK */ *p = 100; /* OK */ Pointer to a cons...
You can use gradle to have BuildConfig constants and res values on a per flavor basis. Just add the value to the flavor you want to support. android { defaultConfig { resValue "string", "app_name", "Full App" buildConfigField "boolean",...
Arrays can be used as plain constants and class constants from version PHP 5.6 onwards: Class constant example class Answer { const C = [2,4]; } print Answer::C[1] . Answer::C[0]; // 42 Plain constant example const ANSWER = [2,4]; print ANSWER[1] . ANSWER[0]; // 42 Also from versi...
VBA defines a number of string constants for special characters like: vbCr : Carriage-Return 'Same as "\r" in C style languages. vbLf : Line-Feed 'Same as "\n" in C style languages. vbCrLf : Carriage-Return & Line-Feed (a new-line in Windows) vbTab: Tab Character vbNul...
Const appName As String = "The App For That"
Giving this enumeration as Example: enum Compass { NORTH(0), EAST(90), SOUTH(180), WEST(270); private int degree; Compass(int deg){ degree = deg; } public int getDegree(){ return degree; } } In Java an enum class is like any other c...
let mySwitch: UISwitch = { view.addSubview($0) $0.addTarget(self, action: "action", forControlEvents: .TouchUpInside) return $0 }(UISwitch())
Headers may be used to declare globally used read-only resources, like string tables for example. Declare those in a separate header which gets included by any file ("Translation Unit") which wants to make use of them. It's handy to use the same header to declare a related enumeration to ...
The Kotlin Standard Library also provides numerous useful functions to iteratively work upon collections. For example, the map function can be used to transform a list of items. val numbers = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 0) val numberStrings = numbers.map { "Number $it" } One of...
Constants in Go may be typed or untyped. For instance, given the following string literal: "bar" one might say that the type of the literal is string, however, this is not semantically correct. Instead, literals are Untyped string constants. It is a string (more correctly, its default ...
In an enum it is possible to define a specific behavior for a particular constant of the enum which overrides the default behavior of the enum, this technique is known as constant specific body. Suppose three piano students - John, Ben and Luke - are defined in an enum named PianoClass, as follows:...

Page 6 of 13