This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From a034498e36c02715b9201646d4ce1ddcddf118c3 Mon Sep 17 00:00:00 2001 | |
From: Shugo Maeda <[email protected]> | |
Date: Wed, 29 Apr 2015 09:14:15 +0900 | |
Subject: [PATCH] support ES6-like hash literals. | |
--- | |
parse.y | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------- | |
1 file changed, 72 insertions(+), 17 deletions(-) | |
diff --git a/parse.y b/parse.y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shamelessly stolen from https://gist.github.com/ileitch/1459987 | |
module InterruptibleSleep | |
def interruptible_sleep(seconds) | |
@sleep_check, @sleep_interrupt = IO.pipe | |
IO.select([@sleep_check], nil, nil, seconds) | |
end | |
def interrupt_sleep | |
@sleep_interrupt.close if @sleep_interrupt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface BananaBox : NSObject | |
- (id)objectAtIndexedSubscript:(NSUInteger)idx; | |
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx; | |
@end | |
@implementation AppleCart | |
NSMutableArray *_bananas; | |
-(id) init { | |
self = [self init] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface Banana : NSObject | |
- (id)objectForKeyedSubscript:(id)key; | |
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; | |
@end | |
@implementation Banana | |
NSMutableDictionary *_attributes; | |
-(id) init { | |
self = [self init]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To add array style subscripting: | |
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx; // setter | |
- (id)objectAtIndexedSubscript:(NSUInteger)idx; // getter | |
// To add dictionary style subscripting | |
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; // setter | |
- (id)objectForKeyedSubscript:(id)key; // getter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSArray *anArray = @[a,b,c]; | |
NSDictionary *aDictionary @{ a : a1, b : b1}; | |
// New subscripting format | |
anArray[0]; // => returns a | |
aDictionary[a] // => returns a1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put this in your ..-Prefix.pch file | |
// Add support for subscripting to the iOS 5 SDK. | |
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 60000 | |
@interface NSObject (SubscriptingSupport) | |
- (id)objectAtIndexedSubscript:(NSUInteger)idx; | |
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx; | |
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; | |
- (id)objectForKeyedSubscript:(id)key; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The problem I have is that I've got a sort_code field in the database, and I want to keep that as one field | |
# BUT I want users to edit it in the form using 3 different fields. | |
# My initial solution was to use virtual attributes and divide it this way. | |
# Can you think of a better way? | |
class Account < ActiveRecord::Base | |
def sort_code_one | |
sort_code[0..1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Banana < ActiveRecord::Base; end | |
banana = Banana.new | |
banana.valid? #=> true | |
banana.singleton_class.validates_presence_of :name | |
banana.valid? #=> true - why did the validation not work? | |
banana.class.validates_presence_of :name | |
banana.valid? #=> false - as we'd expect...but now... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe ApplicationController do | |
describe "current_user" do | |
controller do | |
before_filter :authorize | |
def index | |
end |
NewerOlder