Tutorial by Examples: f

Methods are defined with the def keyword, followed by the method name and an optional list of parameter names in parentheses. The Ruby code between def and end represents the body of the method. def hello(name) "Hello, #{name}" end A method invocation specifies the method name, the...
Many functions in Ruby accept a block as an argument. E.g.: [0, 1, 2].map {|i| i + 1} => [1, 2, 3] If you already have a function that does what you want, you can turn it into a block using &method(:fn): def inc(num) num + 1 end [0, 1, 2].map &method(:inc) => [1, 2, 3]...
There are three basic rules of semicolon insertion: When, as the program is parsed from left to right, a token (called the offending token) is encountered that is not allowed by any production of the grammar, then a semicolon is automatically inserted before the offending token if one or more o...
empty statement var statement expression statement do-while statement continue statement break statement return statement throw statement Examples: When the end of the input stream of tokens is encountered and the parser is unable to parse the input token stream as a single complete Pro...
In performing parsing, before starting, the grammar for the language needs to be specified. A source of tokens is also needed for the parser. The parser could be hand-written code, or a parser generator tool could be used. If a parser generator tool is used, then that tool will need to be downloade...
In this example, we'll be accessing three different resources from Code-behind, each stored in a different scope App.xaml: <Application x:Class="WpfSamples.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http:/...
in this way '0' representing the known values ​​are ranked first, '1' representing the NULL values ​​are sorted by the last: SELECT ID ,REGION ,CITY ,DEPARTMENT ,EMPLOYEES_NUMBER FROM DEPT ORDER BY CASE WHEN REGION IS NULL THEN 1 ELSE 0 END, REGION ...
If you need to send events from fragment to activity, one of the possible solutions is to define callback interface and require that the host activity implement it. Example Send callback to an activity, when fragment's button clicked First of all, define callback interface: public interface Samp...
This is an example for how to handle dynamic key for response. Here A and B are dynamic keys it can be anything Response { "response": [ { "A": [ { "name": "Tango" }, { "name": "P...
The following examples use the UTF-8 encoding to represent filenames (and directory names) on disk. If you want to use another encoding, you should use Encode::encode(...). use v5.14; # Make Perl recognize UTF-8 encoded characters in literal strings. # For this to work: Make sure your text-editor...
Perl does not attempt to decode filenames returned by builtin functions or modules. Such strings representing filenames should always be decoded explicitly, in order for Perl to recognize them as Unicode. use v5.14; use Encode qw(decode_utf8); # Ensure that possible error messages printed to sc...
Some common operations in MATLAB, like differentiation or integration, output results that have a different amount of elements than the input data has. This fact can easily be overlooked, which would usually cause errors like Matrix dimensions must agree. Consider the following example: t = 0:0.1:1...
Polymorphism means that a operation can also be applied to values of some other types. There are multiple types of Polymorphism: Ad hoc polymorphism: contains function overloading. The target is that a Method can be used with different types without the need of being generic. Parametric polym...
You can use parfor to execute the iterations of a loop in parallel: Example: poolobj = parpool(2); % Open a parallel pool with 2 workers s = 0; % Performing some parallel Computations parfor i=0:9 s = s + 1; end disp(s) % Outputs '10' d...
When using C#'s inbuilt lock statement an instance of some type is needed, but its state does not matter. An instance of object is perfect for this: public class ThreadSafe { private static readonly object locker = new object(); public void SomeThreadSafeMethod() { lock (locker) { ...
To create an albums collection, add the following to your config.yml file: collections: - albums Create a corresponding folder at the root of your Jekyll install, named exactly what you put in your config.yml file with an additional prepended underscore; in our example, <source>/_albums....
Even experienced Java developers tend to think that Java has only three protection modifiers. The language actually has four! The package private (a.k.a. default) level of visibility is often forgotten. You should pay attention to what methods you make public. The public methods in an application a...
These Java issues can be very embarrassing, and sometimes remain undiscovered until run in production. Fallthrough behavior in switch statements is often useful; however, missing a “break” keyword when such behavior is not desired can lead to disastrous results. If you have forgotten to put a “break...
Every time a program opens a resource, such as a file or network connection, it is important to free the resource once you are done using it. Similar caution should be taken if any exception were to be thrown during operations on such resources. One could argue that the FileInputStream has a finaliz...
Java manages memory automatically. You are not required to free memory manually. An object's memory on the heap may be freed by a garbage collector when the object is no longer reachable by a live thread. However, you can prevent memory from being freed, by allowing objects to be reachable that are...

Page 196 of 457