Jonathan Clark
Jonathan Clark

Reputation: 20538

Translate objective-c into ruby

I am developing a Rubymotion app. I am using the pod KNSemiModalViewController. How can I "translate" this Objective-C code into ruby?

[self presentSemiViewController:semiVC withOptions:@{
     KNSemiModalOptionKeys.pushParentBack    : @(YES),
     KNSemiModalOptionKeys.animationDuration : @(0.3),
     KNSemiModalOptionKeys.shadowOpacity     : @(0.8),
     }];

Upvotes: 0

Views: 228

Answers (3)

Bachet
Bachet

Reputation: 321

I've seen a Sublime plugin objc2rubymotion, never tried.

There is a web page based on it http://objc2rubymotion.herokuapp.com

Never tried as well but it might help rubyists falling down in iOS environment like me :)

Upvotes: -2

jnoon
jnoon

Reputation: 61

self.presentSemiViewController(semiVC, withOptions:{
  KNSemiModalOptionKeys.pushParentBack => true,
  KNSemiModalOptionKeys.animationDuration => 0.3,
  KNSemiModalOptionKeys.shadowOpacity => 0.8
})

Upvotes: 1

bbum
bbum

Reputation: 162712

You'll have to work out the Ruby side of things yourself, but this line of code:

[self presentSemiViewController:semiVC withOptions:@{
     KNSemiModalOptionKeys.pushParentBack    : @(YES),
     KNSemiModalOptionKeys.animationDuration : @(0.3),
     KNSemiModalOptionKeys.shadowOpacity     : @(0.8),
     }];

Is the same as this:

NSDictionary *dict = [NSDictionary, dictionaryWithObjectsAndKeys:
    [NSNumber numberWithBOOL:YES], KNSemiModalOptionKeys.pushParentBack,
    [NSNumber numberWithFloat:0.3], KNSemiModalOptionKeys.animationDuration,
    [NSNumber numberWithFloat:08], KNSemiModalOptionKeys.shadowOpacity];

[self presentSemiViewController:semiVC withOptions:dict];

Assuming that KNSemiModalOptionKeys.pushParentBack is using dot notation to execute a method, each of those could be rewritten as [KNSemiModalOptionKeys pushParentBack].

Hopefully, that gives you enough info on the ObjC side to translate to Ruby (which is quite adept at forming dictionaries, IIRC).

Upvotes: 2

Related Questions