Tutorial by Examples: e

class Example def example_method :example end def subexample_method :example end def not_missed_method :example end def method_missing name return :example if name == :missing_example_method return :example if name == :missing_subexample_method ...
Ruby moves up on ancestors chain of an object. This chain can contain both modules and classes. Same rules about moving up the chain apply to modules as well. class Example end module Prepended def initialize *args return super :default if args.empty? super end end module Fi...
There are two ways to interrupt messages. Use method_missing to interrupt any non defined message. Define a method in middle of a chain to intercept the message After interrupting messages, it is possible to: Reply to them. Send them somewhere else. Modify the message or its result. ...
The Continue operator works in For, ForEach, While and Do loops. It skips the current iteration of the loop, jumping to the top of the innermost loop. $i =0 while ($i -lt 20) { $i++ if ($i -eq 7) { continue } Write-Host $I } The above will output 1 to 20 to the console but miss...
The break operator will exit a program loop immediately. It can be used in For, ForEach, While and Do loops or in a Switch Statement. $i = 0 while ($i -lt 15) { $i++ if ($i -eq 7) {break} Write-Host $i } The above will count to 15 but stop as soon as 7 is reached. Note: When u...
Prior to Json.NET 4.5 dates were written using the Microsoft format: "/Date(1198908717056)/". If your server sends date in this format you can use the below code to serialize it to NSDate: Objective-C (NSDate*) getDateFromJSON:(NSString *)dateString { // Expect date in this format ...
This can be used in various chat applications, rss feeds, and social apps where you need to have latest feeds with timestamps: Objective-C - (NSString *)getHistoricTimeText:(NSDate *)since { NSString *str; NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:since]; if(in...
Using a file Swift let data = NSData(contentsOfFile: filePath) //assuming filePath is a valid path Objective-C NSData *data = [NSData dataWithContentsOfFile:filePath]; //assuming filePath is a valid path Using a String object Swift let data = (string as NSString).dataUsingEncoding(NSUTF8S...
To String Swift let string = String(NSString(data: data, encoding: NSUTF8StringEncoding)) //assuming data is a valid NSData object Objective-C NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; //assuming data is a valid NSData object [string release]; T...
void methods can be stubbed using the doThrow(), doAnswer(), doNothing(), doCallRealMethod() family of methods. Runnable mock = mock(Runnable.class); doThrow(new UnsupportedOperationException()).when(mock).run(); mock.run(); // throws the UnsupportedOperationException Note thatvoid methods...
This class is called Greeter. Its responsibility is to output a greeting. It has two dependencies. It needs something that will give it the greeting to output, and then it needs a way to output that greeting. Those dependencies are both described as interfaces, IGreetingProvider and IGreetingWriter....
This builds on the previous example of the Greeter class which has two dependencies, IGreetingProvider and IGreetingWriter. The actual implementation of IGreetingProvider might retrieve a string from an API call or a database. The implementation of IGreetingWriter might display the greeting in the ...
Dependency injection means writing classes so that they do not control their dependencies - instead, their dependencies are provided to them ("injected.") This is not the same thing as using a dependency injection framework (often called a "DI container", "IoC container&quo...
Add the I18N nuget package to your MVC project. In web.config, add the i18n.LocalizingModule to your <httpModules> or <modules> section. <!-- IIS 6 --> <httpModules> <add name="i18n.LocalizingModule" type="i18n.LocalizingModule, i18n" /> &...
The java.util.Locale class is used to represent a "geographical, political or cultural" region to localize a given text, number, date or operation to. A Locale object may thus contain a country, region, language, and also a variant of a language, for instance a dialect spoken in a certain ...
Unnamed struct is allowed (type has no name) void foo() { struct /* No name */ { float x; float y; } point; point.x = 42; } or struct Circle { struct /* No name */ { float x; float y; } center; // but a member name float...
This is an example of how to implement custom parameter converters for JAX-RS endpoints. The example shows two classes from Java 8's java.time library. @Provider public class ParamConverters implements ParamConverterProvider { @Override public <T> ParamConverter<T> getConverter...
Name binding is a concept that allows to say to a JAX-RS runtime that a specific filter or interceptor will be executed only for a specific resource method. When a filter or an interceptor is limited only to a specific resource method we say that it is name-bound. Filters and interceptors that do no...
Connection factories are the managed objects that allows application to connect to provider by creating Connection object. javax.jms.ConnectionFactory is an interface that encapsulates configuration parameters defined by an administrator. For using ConnectionFactory client must execute JNDI lookup ...
Given a list: li = [1,2,3,4,5] we can filter a list with a predicate using filter :: (a -> Bool) -> [a] -> [a]: filter (== 1) li -- [1] filter (even) li -- [2,4] filter (odd) li -- [1,3,5] -- Something slightly more complicated comfy i = notTooLarg...

Page 617 of 1191